Skip to content

Commit

Permalink
doc: Update Equations doc with dvisvgm and dvipng references
Browse files Browse the repository at this point in the history
Fixes #619.
  • Loading branch information
kaushalmodi committed Apr 11, 2022
1 parent 3d9cc64 commit c322fe2
Showing 1 changed file with 50 additions and 23 deletions.
73 changes: 50 additions & 23 deletions doc/ox-hugo-manual.org
Expand Up @@ -1453,11 +1453,15 @@ of these is true:
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :mathjax true
:END:
#+begin_description
Supporting {{{latex}}} equations
{{{latex}}} equations support
#+end_description
By default, the inline and block equations are exported to Markdown in
a format that can be rendered using [[https://www.mathjax.org/#gettingstarted][MathJax]]. /You can find one MathJax
config example [[#mathjax-config-example][below]]./

~ox-hugo~ indirectly extends from ~ox-html~ and so it also inherits a
different way of exporting {{{latex}}} equations --- by [[#exporting-equations-to-images][exporting them
to images]].
**** Inline equations
- Inline equations are wrapped between =\(= and =\)=.
- =$= wrapping also works, but it is not preferred as it comes with
Expand All @@ -1477,29 +1481,26 @@ For example, below in Org:
LaTeX formatted equation: \( E = -J \sum_{i=1}^N s_i s_{i+1} \)
#+end_src

will look like this in Hugo rendered HTML:
will look like this in Hugo rendered HTML (using MathJax):

LaTeX formatted equation: \( E = -J \sum_{i=1}^N s_i s_{i+1 }\)

*Don't see this in Markdown, see what it looks after Hugo has
processed it.* --- =ox-hugo= does some heavy escaping to get around a
Blackfriday issue with supporting MathJax syntax equations (that Org
supports).

Here's another example, taken from [[https://orgmode.org/manual/LaTeX-fragments.html][(org) LaTeX fragments]].
Here's another example, taken from [[info:org#LaTeX fragments]]:

Below in Org:
#+begin_example
If $a^2=b$ and \( b=2 \), then the solution must be either
$$ a=+\sqrt{2} $$ or \[ a=-\sqrt{2} \]
#+end_example

renders to:
Above renders to below using Mathjax:

If $a^2=b$ and \( b=2 \), then the solution must be either
$$ a=+\sqrt{2} $$ or \[ a=-\sqrt{2} \]

(Note that the last two equations show up on their own lines.)
#+begin_note
Note that the last two equations show up on their own lines because
those equations are wrapped in ~\[ .. \]~.
#+end_note
**** {{{latex}}} Environments
=ox-hugo= support {{{latex}}} environments.

Expand All @@ -1512,25 +1513,50 @@ C = W\log_{2} (1+\mathrm{SNR})
\end{equation}
#+end_src

will export as:
will render as below using MathJax:

\begin{equation}
\label{eq:1}
C = W\log_{2} (1+\mathrm{SNR})
\end{equation}

Equation referencing will also work[fn:3]. So =\ref{eq:1}= will render as
\ref{eq:1}.
**** Examples
You can find many examples by looking at {{{testtag(equations)}}}.
#+begin_note
You can find many more equation examples at {{{testtag(equations)}}}.
#+end_note
***** Referencing Equations
Equation referencing will also work **but it requires MathJax**. [[#mathjax-config-example][Here]]
is a MathJax configuration that is known to work for this referencing
feature. =\label{SOMELABEL}= labeled equations can be referenced using
=\ref{SOMELABEL}=[fn:12]. So =\ref{eq:1}= will render as \ref{eq:1}
and link to the equation above.
**** MathJax config example
:PROPERTIES:
:CUSTOM_ID: mathjax-config-example
:END:
Here's how MathJax is configured for this website:

1. hugo-onyx-theme [[https://github.com/kaushalmodi/hugo-onyx-theme/blob/master/layouts/partials/mathjax.html][~mathjax.html~ partial]]:
2. MathJax config ( [[https://github.com/kaushalmodi/hugo-onyx-theme/blob/master/static/js/mathjax-config.js][~js/mathjax-config.js~]] ):
- hugo-onyx-theme [[https://github.com/kaushalmodi/hugo-onyx-theme/blob/master/layouts/partials/mathjax.html][~mathjax.html~ partial]]
- MathJax config: [[https://github.com/kaushalmodi/hugo-onyx-theme/blob/master/static/js/mathjax-config.js][~js/mathjax-config.js~]]
**** Exporting {{{latex}}} equations as images
:PROPERTIES:
:CUSTOM_ID: exporting-equations-to-images
:END:
If you prefer, you can using ~dvisvgm~ or ~dvipng~[fn:3] to export the
equations to SVG or PNG images, and the equations in the Org file will
be replaced by links to those images in the exported Markdown files.

The method for exporting the equations to images is the same as that
documented for ~ox-html~ in [[info:org#Math formatting in HTML export]]:
- To export the equations to SVG, add ~#+options: tex:dvisvgm~ to the
top of your Org file, or add ~:EXPORT_OPTIONS: tex:dvisvgm~ to the
post subtree's property drawer.
- Similarly, to export the equations to PNG, use the ~tex:dvipng~
option instead.

#+begin_note
Referencing to equations using ~\ref{..}~ will not work if equations
are exported as images.
#+end_note
*** Tags and Categories
:PROPERTIES:
:EXPORT_FILE_NAME: tags-and-categories
Expand Down Expand Up @@ -4661,6 +4687,12 @@ Categories,)}}}.
* Footnotes




[fn:3] The ~dvisvgm~ and ~dvipng~ executables ship with TexLive
distributions.

[fn:12] This same MathJax setup is used on the =ox-hugo= test site too.
[fn:11] If you are looking for ~EXPORT_HUGO_SECTION*~ property, that
has been deprecated; please see {{{titleref(Deprecation
Notices#export-hugo-section-frag)}}}.
Expand Down Expand Up @@ -4696,11 +4728,6 @@ the default ~DONE~. And similarly, use your custom "TODO" keyword
instead of the default ~TODO~ (ensure that it is *not* in
~org-done-keywords~).

[fn:3] This requires MathJax. [[https://github.com/kaushalmodi/hugo-bare-min-theme/blob/master/layouts/partials/mathjax.html][Here]] is a MathJax configuration that is
tested to work for equation referencing (referencing =\label{}=
labeled equations using =\ref{}=). The same is used on the =ox-hugo=
test site too.

[fn:2] For only subtree-based exports, you can set that special tag as
Org style tags too. Example: ~* I don't want to export this post
:no_no_dont_export:~.. and don't forget to add that tag to
Expand Down

0 comments on commit c322fe2

Please sign in to comment.