From cbda3645fd5dc052e7372dc0b421886a34cae93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Sat, 12 Aug 2023 13:53:40 +0200 Subject: [PATCH 01/16] Add latex theme --- src/Makie.jl | 1 + src/themes/theme_latex.jl | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 src/themes/theme_latex.jl diff --git a/src/Makie.jl b/src/Makie.jl index 2fc66e042f0..4b24974683e 100644 --- a/src/Makie.jl +++ b/src/Makie.jl @@ -207,6 +207,7 @@ export theme_black export theme_minimal export theme_light export theme_dark +export theme_latex export xticklabels, yticklabels, zticklabels export xtickrange, ytickrange, ztickrange diff --git a/src/themes/theme_latex.jl b/src/themes/theme_latex.jl new file mode 100644 index 00000000000..c4e89b9f716 --- /dev/null +++ b/src/themes/theme_latex.jl @@ -0,0 +1,10 @@ +function theme_latex() + Theme( + fonts = Attributes( + :bold => texfont(:bold), + :bolditalic => texfont(:bolditalic), + :italic => texfont(:italic), + :regular => texfont(:regular) + ) + ) +end From 2cc9ef416c86c4c726a726239eb4b0926275829a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Sat, 12 Aug 2023 14:09:58 +0200 Subject: [PATCH 02/16] Add a bit of doc --- NEWS.md | 1 + docs/documentation/latex.md | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/NEWS.md b/NEWS.md index e35c93833e7..e77ab129150 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ - Added `xreversed`, `yreversed` and `zreversed` attributes to `Axis3` [#3138](https://github.com/MakieOrg/Makie.jl/pull/3138). - Fixed incorrect placement of contourlabels with transform functions [#3083](https://github.com/MakieOrg/Makie.jl/pull/3083) - Fixed automatic normal generation for meshes with shading and no normals [#3041](https://github.com/MakieOrg/Makie.jl/pull/3041). +- Added a `latex_theme` that uses the latex font family as default fonts. ## v0.19.7 diff --git a/docs/documentation/latex.md b/docs/documentation/latex.md index 9dc77f52eff..08af1a03aed 100644 --- a/docs/documentation/latex.md +++ b/docs/documentation/latex.md @@ -47,3 +47,23 @@ Axis(f[1,1], title=L"Some %$(t) and some math: $\frac{2\alpha+1}{y}$") f ``` \end{examplefigure} + +## Uniformizing the fonts + +We provide a LaTeX theme to easily switch to the LaTeX default fonts for all the text. + +\begin{examplefigure}{svg = true} +```julia +using CairoMakie +CairoMakie.activate!() # hide + +set_theme!(theme_latex()) + +fig = Figure() +Label(fig[1, 1], "A standard Label", tellwidth = false) +Label(fig[2, 1], L"A LaTeXString with a small formula $x^2$", tellwidth = false) +Axis(fig[3, 1], title = "An axis with matching font for the tick labels") + +fig +``` +\end{examplefigure} \ No newline at end of file From 71ce90572d5cbb36c151c711f9f52f539c810397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Sun, 13 Aug 2023 13:00:40 +0200 Subject: [PATCH 03/16] Up NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e77ab129150..cac8c61814a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,7 +5,7 @@ - Added `xreversed`, `yreversed` and `zreversed` attributes to `Axis3` [#3138](https://github.com/MakieOrg/Makie.jl/pull/3138). - Fixed incorrect placement of contourlabels with transform functions [#3083](https://github.com/MakieOrg/Makie.jl/pull/3083) - Fixed automatic normal generation for meshes with shading and no normals [#3041](https://github.com/MakieOrg/Makie.jl/pull/3041). -- Added a `latex_theme` that uses the latex font family as default fonts. +- Added a theme `theme_latexfonts` that uses the latex font family as default fonts [#3147](https://github.com/MakieOrg/Makie.jl/pull/3147). ## v0.19.7 From 485c0b759b1b0338c06fc1f01d1f01e8139b89f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Sun, 13 Aug 2023 13:10:01 +0200 Subject: [PATCH 04/16] Rename to theme_latexfonts --- docs/documentation/latex.md | 2 +- src/Makie.jl | 3 ++- src/themes/{theme_latex.jl => theme_latexfonts.jl} | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) rename src/themes/{theme_latex.jl => theme_latexfonts.jl} (89%) diff --git a/docs/documentation/latex.md b/docs/documentation/latex.md index 08af1a03aed..9bf698ad1ad 100644 --- a/docs/documentation/latex.md +++ b/docs/documentation/latex.md @@ -57,7 +57,7 @@ We provide a LaTeX theme to easily switch to the LaTeX default fonts for all the using CairoMakie CairoMakie.activate!() # hide -set_theme!(theme_latex()) +set_theme!(theme_latexfonts()) fig = Figure() Label(fig[1, 1], "A standard Label", tellwidth = false) diff --git a/src/Makie.jl b/src/Makie.jl index 4b24974683e..0620daf9900 100644 --- a/src/Makie.jl +++ b/src/Makie.jl @@ -118,6 +118,7 @@ include("themes/theme_black.jl") include("themes/theme_minimal.jl") include("themes/theme_light.jl") include("themes/theme_dark.jl") +include("themes/theme_latexfonts.jl") # camera types + functions include("camera/projection_math.jl") @@ -207,7 +208,7 @@ export theme_black export theme_minimal export theme_light export theme_dark -export theme_latex +export theme_latexfonts export xticklabels, yticklabels, zticklabels export xtickrange, ytickrange, ztickrange diff --git a/src/themes/theme_latex.jl b/src/themes/theme_latexfonts.jl similarity index 89% rename from src/themes/theme_latex.jl rename to src/themes/theme_latexfonts.jl index c4e89b9f716..e019547959e 100644 --- a/src/themes/theme_latex.jl +++ b/src/themes/theme_latexfonts.jl @@ -1,4 +1,4 @@ -function theme_latex() +function theme_latexfonts() Theme( fonts = Attributes( :bold => texfont(:bold), From e67dee7b3b653671c6bc7d494501c54ba59802f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Sun, 13 Aug 2023 13:59:07 +0200 Subject: [PATCH 05/16] Add merge doc --- docs/documentation/theming.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 3b7ad8bdfba..2f345fce178 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -29,6 +29,8 @@ function example_plot() for i in 1:2, j in 1:2 lines(f[i, j], cumsum(randn(50))) end + Label(f[0, :], "A simple example plot") + Label(f[3, :], L"Random walks $x(t_n) = \sum_{i \leq n} z_i") f end @@ -53,12 +55,32 @@ This theme will be active until we call `set_theme!()`. set_theme!() ``` +## merge + +Themes often only affect part of the plot attributes. Therefore it is possible to combine themes to get their respective effects together. + +For example, you can combine the dark theme with the LaTeX fonts theme to have both the dark colors and uniform fonts. + +\begin{examplefigure}{} +```julia +dark_latexfonts = merge(theme_dark(), theme_latexfonts()) +set_theme!(dark_latexfonts) +example_plot() +``` +\end{examplefigure} + ## update_theme! If you have activated a theme already and want to update it partially, without removing the attributes not in the new theme, you can use `update_theme!`. -For example, you can first call `set_theme!(my_theme)` and later update font and fontsize with `update_theme!(font = "Arial", fontsize = 18)`, leaving all other settings intact. +For example, you can decide to change the text size after activating the dark and latex theme in the previous section. +\begin{examplefigure}{} +```julia +update_theme!(fontsize=30) +example_plot() +``` +\end{examplefigure} ## with_theme From aa12e8499244b32970c58495eea997e35bd22435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Fri, 18 Aug 2023 20:29:27 +0200 Subject: [PATCH 06/16] Revert to base theme in example --- docs/documentation/theming.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 2f345fce178..053909de742 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -23,7 +23,6 @@ Let's create a plot with the default theme: using CairoMakie CairoMakie.activate!() # hide - function example_plot() f = Figure() for i in 1:2, j in 1:2 @@ -66,6 +65,8 @@ For example, you can combine the dark theme with the LaTeX fonts theme to have b dark_latexfonts = merge(theme_dark(), theme_latexfonts()) set_theme!(dark_latexfonts) example_plot() + +set_theme!() # hide ``` \end{examplefigure} @@ -79,6 +80,8 @@ For example, you can decide to change the text size after activating the dark an ```julia update_theme!(fontsize=30) example_plot() + +set_theme!() # hide ``` \end{examplefigure} From d8525a29ded7f288ad665685ab9effa38f86d31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Sat, 19 Aug 2023 01:51:35 +0200 Subject: [PATCH 07/16] Fix theming.md --- docs/documentation/theming.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 053909de742..9655ba32565 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -29,9 +29,7 @@ function example_plot() lines(f[i, j], cumsum(randn(50))) end Label(f[0, :], "A simple example plot") - Label(f[3, :], L"Random walks $x(t_n) = \sum_{i \leq n} z_i") - f -end + Label(f[3, :], L"Random walks $x(t_n)$") example_plot() ``` @@ -65,8 +63,6 @@ For example, you can combine the dark theme with the LaTeX fonts theme to have b dark_latexfonts = merge(theme_dark(), theme_latexfonts()) set_theme!(dark_latexfonts) example_plot() - -set_theme!() # hide ``` \end{examplefigure} @@ -80,11 +76,13 @@ For example, you can decide to change the text size after activating the dark an ```julia update_theme!(fontsize=30) example_plot() - -set_theme!() # hide ``` \end{examplefigure} +```! +# hideall +set_theme!() +``` ## with_theme Because it can be tedious to remember to switch themes off which you need only temporarily, there's the function `with_theme(f, theme)` which handles the resetting for you automatically, even if you encounter an error while running `f`. From ef9b058e66bbdc223d02fd652505a8cc81a9feb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Sat, 19 Aug 2023 02:15:45 +0200 Subject: [PATCH 08/16] Try one more thing to fix doc --- docs/documentation/theming.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 9655ba32565..7f840e973ca 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -79,16 +79,13 @@ example_plot() ``` \end{examplefigure} -```! -# hideall -set_theme!() -``` ## with_theme Because it can be tedious to remember to switch themes off which you need only temporarily, there's the function `with_theme(f, theme)` which handles the resetting for you automatically, even if you encounter an error while running `f`. \begin{examplefigure}{} ```julia +set_theme!() # hide with_theme(fontsize_theme) do example_plot() end From 7ad06858b14721e7c649a998563542e06b69c16d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Sat, 19 Aug 2023 12:25:39 +0200 Subject: [PATCH 09/16] Fix theming.md for real I guess --- docs/documentation/theming.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 7f840e973ca..3d71888711c 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -30,6 +30,7 @@ function example_plot() end Label(f[0, :], "A simple example plot") Label(f[3, :], L"Random walks $x(t_n)$") +end example_plot() ``` From 21f05d3a0bb13e121d746205f8a591ecf8f3e8fd Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 23 Aug 2023 10:22:23 +0200 Subject: [PATCH 10/16] try importing L_str directly in code block --- docs/documentation/theming.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 3d71888711c..3b0ecffdc23 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -22,6 +22,7 @@ Let's create a plot with the default theme: ```julia using CairoMakie CairoMakie.activate!() # hide +using Makie.LaTeXStrings: @L_str # hide function example_plot() f = Figure() From feea0d65c1a8f759e08eccebb13b15e9429c2096 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 23 Aug 2023 15:54:52 +0200 Subject: [PATCH 11/16] Update theming.md --- docs/documentation/theming.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 3b0ecffdc23..84738db22f1 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -22,7 +22,7 @@ Let's create a plot with the default theme: ```julia using CairoMakie CairoMakie.activate!() # hide -using Makie.LaTeXStrings: @L_str # hide +using Makie.LaTeXStrings # hide function example_plot() f = Figure() @@ -30,7 +30,7 @@ function example_plot() lines(f[i, j], cumsum(randn(50))) end Label(f[0, :], "A simple example plot") - Label(f[3, :], L"Random walks $x(t_n)$") + Label(f[3, :], LaTeXStrings.L"Random walks $x(t_n)$") end example_plot() From bac59ee9a1be1faf925b035e39f126f0a9bed1ab Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 23 Aug 2023 16:27:38 +0200 Subject: [PATCH 12/16] try fully qualified --- docs/documentation/theming.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 84738db22f1..8b47f999a8c 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -30,7 +30,7 @@ function example_plot() lines(f[i, j], cumsum(randn(50))) end Label(f[0, :], "A simple example plot") - Label(f[3, :], LaTeXStrings.L"Random walks $x(t_n)$") + Label(f[3, :], Makie.LaTeXStrings.L"Random walks $x(t_n)$") end example_plot() From 19391073a70f9e8c1ff076582a947701076c6323 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 23 Aug 2023 17:19:39 +0200 Subject: [PATCH 13/16] could it be the parser that's confused? --- docs/documentation/theming.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 8b47f999a8c..5219f483b24 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -30,7 +30,7 @@ function example_plot() lines(f[i, j], cumsum(randn(50))) end Label(f[0, :], "A simple example plot") - Label(f[3, :], Makie.LaTeXStrings.L"Random walks $x(t_n)$") + Label(f[3, :], L"\sum_a^b{xy} + \mathscr{L}") end example_plot() From 5ec743ff1e36de72c5bc4b268196bd3eb752950e Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 23 Aug 2023 18:11:24 +0200 Subject: [PATCH 14/16] Update theming.md --- docs/documentation/theming.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 5219f483b24..27120f03100 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -30,7 +30,6 @@ function example_plot() lines(f[i, j], cumsum(randn(50))) end Label(f[0, :], "A simple example plot") - Label(f[3, :], L"\sum_a^b{xy} + \mathscr{L}") end example_plot() From 24a19d73f98d2bc7d2edea11fe4850b8df8afbb9 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 24 Aug 2023 11:42:07 +0200 Subject: [PATCH 15/16] Update theming.md --- docs/documentation/theming.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 27120f03100..b062a086afa 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -30,6 +30,7 @@ function example_plot() lines(f[i, j], cumsum(randn(50))) end Label(f[0, :], "A simple example plot") + f end example_plot() From 1e15b8f4773628ea5ae66834d3da4f30c499ed5d Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 24 Aug 2023 12:22:53 +0200 Subject: [PATCH 16/16] last try! --- docs/documentation/theming.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index b062a086afa..49746084d42 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -30,6 +30,7 @@ function example_plot() lines(f[i, j], cumsum(randn(50))) end Label(f[0, :], "A simple example plot") + Label(f[3, :], L"Random walks $x(t_n)$") f end @@ -41,6 +42,7 @@ Now we define a theme which changes the default fontsize, activate it, and plot. \begin{examplefigure}{} ```julia +using CairoMakie, Makie.LaTeXStrings # hide fontsize_theme = Theme(fontsize = 10) set_theme!(fontsize_theme) @@ -62,6 +64,7 @@ For example, you can combine the dark theme with the LaTeX fonts theme to have b \begin{examplefigure}{} ```julia +using CairoMakie, Makie.LaTeXStrings # hide dark_latexfonts = merge(theme_dark(), theme_latexfonts()) set_theme!(dark_latexfonts) example_plot() @@ -76,6 +79,7 @@ For example, you can decide to change the text size after activating the dark an \begin{examplefigure}{} ```julia +using CairoMakie, Makie.LaTeXStrings # hide update_theme!(fontsize=30) example_plot() ``` @@ -87,6 +91,7 @@ Because it can be tedious to remember to switch themes off which you need only t \begin{examplefigure}{} ```julia +using CairoMakie, Makie.LaTeXStrings # hide set_theme!() # hide with_theme(fontsize_theme) do example_plot() @@ -98,6 +103,7 @@ You can also pass additional keywords to add or override attributes in your them \begin{examplefigure}{} ```julia +using CairoMakie, Makie.LaTeXStrings # hide with_theme(fontsize_theme, fontsize = 25) do example_plot() end @@ -110,6 +116,7 @@ You can theme plot objects by using their uppercase type names as a key in your \begin{examplefigure}{} ```julia +using CairoMakie, Makie.LaTeXStrings # hide lines_theme = Theme( Lines = ( linewidth = 4, @@ -129,6 +136,7 @@ Here is how you could define a simple ggplot-like style for your axes: \begin{examplefigure}{} ```julia +using CairoMakie, Makie.LaTeXStrings # hide ggplot_theme = Theme( Axis = ( backgroundcolor = :gray90,