diff --git a/NEWS.md b/NEWS.md index 1293e36a138..1a3f0ccc09a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,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 theme `theme_latexfonts` that uses the latex font family as default fonts [#3147](https://github.com/MakieOrg/Makie.jl/pull/3147). - Added the `triplot` and `voronoiplot` recipes from DelaunayTriangulation.jl [#3102](https://github.com/MakieOrg/Makie.jl/pull/3102), [#3159](https://github.com/MakieOrg/Makie.jl/pull/3159). ## v0.19.7 diff --git a/docs/documentation/latex.md b/docs/documentation/latex.md index 9dc77f52eff..9bf698ad1ad 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_latexfonts()) + +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 diff --git a/docs/documentation/theming.md b/docs/documentation/theming.md index 3b7ad8bdfba..49746084d42 100644 --- a/docs/documentation/theming.md +++ b/docs/documentation/theming.md @@ -22,13 +22,15 @@ Let's create a plot with the default theme: ```julia using CairoMakie CairoMakie.activate!() # hide - +using Makie.LaTeXStrings # hide function example_plot() f = Figure() 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)$") f end @@ -40,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) @@ -53,12 +56,34 @@ 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 +using CairoMakie, Makie.LaTeXStrings # hide +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 +using CairoMakie, Makie.LaTeXStrings # hide +update_theme!(fontsize=30) +example_plot() +``` +\end{examplefigure} ## with_theme @@ -66,6 +91,8 @@ 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() end @@ -76,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 @@ -88,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, @@ -107,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, diff --git a/src/Makie.jl b/src/Makie.jl index e37ec8d431a..11c719e6f70 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") @@ -209,6 +210,7 @@ export theme_black export theme_minimal export theme_light export theme_dark +export theme_latexfonts export xticklabels, yticklabels, zticklabels export xtickrange, ytickrange, ztickrange diff --git a/src/themes/theme_latexfonts.jl b/src/themes/theme_latexfonts.jl new file mode 100644 index 00000000000..e019547959e --- /dev/null +++ b/src/themes/theme_latexfonts.jl @@ -0,0 +1,10 @@ +function theme_latexfonts() + Theme( + fonts = Attributes( + :bold => texfont(:bold), + :bolditalic => texfont(:bolditalic), + :italic => texfont(:italic), + :regular => texfont(:regular) + ) + ) +end