diff --git a/example-site/content-org/all-posts.org b/example-site/content-org/all-posts.org index 149151e..c66683a 100644 --- a/example-site/content-org/all-posts.org +++ b/example-site/content-org/all-posts.org @@ -690,22 +690,45 @@ This gets both categories =catA= and =catB=. :EXPORT_FILE_NAME: equation-latex-frag :EXPORT_DATE: 2017-07-31 :END: -Wrap the equations between =\(= and =\)=. +- Inline equations are wrapped between =\(= and =\)=. + - =$= wrapping also works, but it is not preferred as it comes with + restrictions like "there should be no whitespace between the + equation and the =$= delimiters". + + So =$ a=b $= will not work (it will look like: $ a=b $), but + =$a=b$= will work (it will look like: $a=b$). + + On the other hand, both =\(a=b\)= (it will look like: \(a=b\)) and + =\( a=b \)= (it will look like: \( a=b \)) will work. +- One-per-line equations are wrapped between =\[= and =\]= or =$$= + delimiters. For example, below in Org: #+BEGIN_SRC text LaTeX formatted equation: \( E = -J \sum_{i=1}^N s_i s_{i+1} \) #+END_SRC -will look like this in Hugo rendered HTML (don't see this in Markdown, -see what it looks after Hugo has processed it). +will look like this in Hugo rendered HTML: LaTeX formatted equation: \( E = -J \sum_{i=1}^N s_i s_{i+1 }\) -Here's another example similar to one in [[http://orgmode.org/manual/LaTeX-fragments.html][(org) LaTeX fragments]]. +(Don't see this in Markdown, see what it looks after Hugo has +processed it.) + +Here's another example, taken from [[http://orgmode.org/manual/LaTeX-fragments.html][(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}\). +$$ a=+\sqrt{2} $$ or \[ a=-\sqrt{2} \] +#+END_EXAMPLE + +renders to: + +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.) * TODO Pre-Draft State :PROPERTIES: :EXPORT_FILE_NAME: draft-state-todo diff --git a/example-site/content/posts/equation-latex-frag.md b/example-site/content/posts/equation-latex-frag.md index 75b42e2..dc13ba2 100644 --- a/example-site/content/posts/equation-latex-frag.md +++ b/example-site/content/posts/equation-latex-frag.md @@ -5,7 +5,18 @@ tags = ["equations"] draft = false +++ -Wrap the equations between `\(` and `\)`. +- Inline equations are wrapped between `\(` and `\)`. + - `$` wrapping also works, but it is not preferred as it comes with + restrictions like "there should be no whitespace between the + equation and the `$` delimiters". + + So `$ a=b $` will not work (it will look like: $ a=b $), but + `$a=b$` will work (it will look like: \\(a=b\\)). + + On the other hand, both `\(a=b\)` (it will look like: \\(a=b\\)) and + `\( a=b \)` (it will look like: \\( a=b \\)) will work. +- One-per-line equations are wrapped between `\[` and `\]` or `$$` + delimiters. For example, below in Org: @@ -13,12 +24,25 @@ For example, below in Org: LaTeX formatted equation: \( E = -J \sum_{i=1}^N s_i s_{i+1} \) ``` -will look like this in Hugo rendered HTML (don't see this in Markdown, -see what it looks after Hugo has processed it). +will look like this in Hugo rendered HTML: LaTeX formatted equation: \\( E = -J \sum\_{i=1}^N s\_i s\_{i+1 }\\) -Here's another example similar to one in [(org) LaTeX fragments](http://orgmode.org/manual/LaTeX-fragments.html). +(Don't see this in Markdown, see what it looks after Hugo has +processed it.) + +Here's another example, taken from [(org) LaTeX fragments](http://orgmode.org/manual/LaTeX-fragments.html). + +Below in Org: + +```text +If $a^2=b$ and \( b=2 \), then the solution must be either +$$ a=+\sqrt{2} $$ or \[ a=-\sqrt{2} \] +``` + +renders to: If \\(a^2=b\\) and \\( b=2 \\), then the solution must be either -\\(a=+\sqrt{2}\\) or \\(a=-\sqrt{2}\\). +\\[ a=+\sqrt{2} \\] or \\[ a=-\sqrt{2} \\] + +(Note that the last two equations show up on their own lines.) diff --git a/ox-blackfriday.el b/ox-blackfriday.el index f597658..5c1aa06 100644 --- a/ox-blackfriday.el +++ b/ox-blackfriday.el @@ -109,8 +109,11 @@ INFO is a plist holding contextual information." ((memq processing-type '(t mathjax)) (let* ((frag (org-html-format-latex latex-frag 'mathjax info)) ;; https://gohugo.io/content-management/formats#solution - (frag (replace-regexp-in-string "\\(\\\\[()]\\)" "\\\\\\1" frag)) ;\( -> \\(, \) -> \\) - (frag (replace-regexp-in-string "_" "\\\\_" frag))) ;_ -> \_ + (frag (replace-regexp-in-string "_" "\\\\_" frag)) ;_ -> \_ + ;; Need to escape the backslash in "\(", "\)", .. to + ;; make Blackfriday happy. So \( -> \\(, \) -> \\), + ;; \[ -> \\[ and \] -> \\]. + (frag (replace-regexp-in-string "\\(\\\\[]()[]\\)" "\\\\\\1" frag))) frag)) ((assq processing-type org-preview-latex-process-alist) (let ((formula-link