From 4e04b48f49650a95849b0e3fa401269b0c1e9f4d Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 17:56:36 +0200 Subject: [PATCH 01/50] new file: README.md new file: displaymath2svg.lua --- displaymath2svg/README.md | 61 ++++++++++++++++++++ displaymath2svg/displaymath2svg.lua | 87 +++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 displaymath2svg/README.md create mode 100644 displaymath2svg/displaymath2svg.lua diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md new file mode 100644 index 00000000..046bc65d --- /dev/null +++ b/displaymath2svg/README.md @@ -0,0 +1,61 @@ +# Description + +This Lua filter for Pandoc converts LaTeX DisplayMath to MathJax generated SVG +in any of the available MathJax fonts. + +This is useful when CSS paged media engines cannot process complex JavaScript +as required by MathJax. + +See: for information about CSS paged media, a W3C +standard. + +This filter also defines the missing LaTeX commands `\j` and `\e{}` for displaying +the imaginary unit j and the exponential function with Euler constant e. + + +# Requires + +```bash +$ sudo apt install pandoc pandoc-citeproc libghc-pandoc-prof nodejs npm +$ sudo npm install --global mathjax-node-cli +``` + + +# Usage + +To be used as a [Pandoc Lua filter](https://pandoc.org/lua-filters.html). + +```bash +pandoc --mathml --filter='displaymath2svg.lua' +``` + + +# Privacy + +No Internet connection is established when creating MathJax SVG code using +tex2svg. Hence, formulas in SVG can be created offline and remain private. + + +# Copyright + +Copyright 2020 Serge Y. Stroobandt + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + + +# Contact + +```bash +$ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d +``` diff --git a/displaymath2svg/displaymath2svg.lua b/displaymath2svg/displaymath2svg.lua new file mode 100644 index 00000000..93d30c73 --- /dev/null +++ b/displaymath2svg/displaymath2svg.lua @@ -0,0 +1,87 @@ +-- DESCRIPTION +-- +-- This Lua filter for Pandoc converts LaTeX DisplayMath to MathJax generated SVG +-- in any of the available MathJax fonts. +-- +-- This is useful when CSS paged media engines cannot process complex JavaScript +-- as required by MathJax. +-- +-- See: https://www.print-css.rocks for information about CSS paged media, a W3C +-- standard. +-- +-- This filter also defines the missing LaTeX commands \j and \e{} for displaying +-- the imaginary unit j and the exponential function with Euler constant e. + + +-- REQUIRES +-- +-- $ sudo apt install pandoc pandoc-citeproc libghc-pandoc-prof nodejs npm +-- $ sudo npm install --global mathjax-node-cli + + +-- USAGE +-- +-- To be used as a Pandoc Lua filter. +-- pandoc --mathml --filter='displaymath2svg.lua' +-- +-- See also: https://pandoc.org/lua-filters.html + + +-- PRIVACY +-- +-- No Internet connection is established when creating MathJax SVG code using +-- tex2svg. Hence, formulas in SVG can be created offline and remain private. + + +-- COPYRIGHT +-- +-- Copyright 2020 Serge Y. Stroobandt +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + + +-- CONTACT +-- +-- $ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d + + +-- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html +local font = 'Gyre-Pagella' + + +-- Some missing LaTeX math commands are defined here: +local newcommands = '\\newcommand{\\j}{{\\text{j}}}\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}' + + +-- The available options for tex2svg are: + --help Show help [boolean] + --version Show version number [boolean] + --inline process as in-line TeX [boolean] + --speech include speech text [boolean] [default: true] + --linebreaks perform automatic line-breaking [boolean] + --font web font to use [default: "TeX"] + --ex ex-size in pixels [default: 6] + --width width of container in ex [default: 100] + --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] + + +function Math(elem) + if elem.mathtype == 'DisplayMath' then + local svg = pandoc.pipe('/usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg', {'--speech=false', '--font', font, newcommands .. elem.text}, '') + if FORMAT:match '^html.?' then + svg = '
' .. svg .. '
' + end + return pandoc.RawInline(FORMAT, svg) + end +end From 48125691f938ee2e4e90433c95fc5803400dece9 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 17:59:26 +0200 Subject: [PATCH 02/50] modified: displaymath2svg README.md --- displaymath2svg/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index 046bc65d..89c0f5ff 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -2,10 +2,8 @@ This Lua filter for Pandoc converts LaTeX DisplayMath to MathJax generated SVG in any of the available MathJax fonts. - This is useful when CSS paged media engines cannot process complex JavaScript as required by MathJax. - See: for information about CSS paged media, a W3C standard. From d51a163006dd960aa3bee332381a0794267a464d Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 18:05:29 +0200 Subject: [PATCH 03/50] modified: README.md modified: displaymath2svg.lua --- displaymath2svg/README.md | 5 +++-- displaymath2svg/displaymath2svg.lua | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index 89c0f5ff..b1af2d86 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -2,7 +2,8 @@ This Lua filter for Pandoc converts LaTeX DisplayMath to MathJax generated SVG in any of the available MathJax fonts. -This is useful when CSS paged media engines cannot process complex JavaScript + +This is useful when a CSS paged media engine cannot process complex JavaScript as required by MathJax. See: for information about CSS paged media, a W3C standard. @@ -31,7 +32,7 @@ pandoc --mathml --filter='displaymath2svg.lua' # Privacy No Internet connection is established when creating MathJax SVG code using -tex2svg. Hence, formulas in SVG can be created offline and remain private. +`tex2svg`. Hence, formulas in SVG can be created offline and remain private. # Copyright diff --git a/displaymath2svg/displaymath2svg.lua b/displaymath2svg/displaymath2svg.lua index 93d30c73..597d1deb 100644 --- a/displaymath2svg/displaymath2svg.lua +++ b/displaymath2svg/displaymath2svg.lua @@ -3,7 +3,7 @@ -- This Lua filter for Pandoc converts LaTeX DisplayMath to MathJax generated SVG -- in any of the available MathJax fonts. -- --- This is useful when CSS paged media engines cannot process complex JavaScript +-- This is useful when a CSS paged media engine cannot process complex JavaScript -- as required by MathJax. -- -- See: https://www.print-css.rocks for information about CSS paged media, a W3C From 2d303346634f2f66b960959a2426f0be8982f775 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 20:08:06 +0200 Subject: [PATCH 04/50] modified: README.md modified: displaymath2svg.lua --- displaymath2svg/README.md | 12 ++++++++---- displaymath2svg/displaymath2svg.lua | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index b1af2d86..e0e60268 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -1,12 +1,16 @@ # Description -This Lua filter for Pandoc converts LaTeX DisplayMath to MathJax generated SVG -in any of the available MathJax fonts. +This [Lua filter](https://pandoc.org/lua-filters.html) +for [Pandoc](https://pandoc.org/) +converts [LaTeX DisplayMath](https://en.wikibooks.org/wiki/LaTeX/Mathematics) +to [MathJax](https://www.mathjax.org/) generated +[scalable vector graphics (SVG)](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) +in any of the available [MathJax fonts](https://docs.mathjax.org/en/latest/output/fonts.html). This is useful when a CSS paged media engine cannot process complex JavaScript as required by MathJax. -See: for information about CSS paged media, a W3C -standard. +See: for information about CSS paged media, +a [W3C standard](https://www.w3.org/TR/css-page-3/). This filter also defines the missing LaTeX commands `\j` and `\e{}` for displaying the imaginary unit j and the exponential function with Euler constant e. diff --git a/displaymath2svg/displaymath2svg.lua b/displaymath2svg/displaymath2svg.lua index 597d1deb..c3e753b9 100644 --- a/displaymath2svg/displaymath2svg.lua +++ b/displaymath2svg/displaymath2svg.lua @@ -1,7 +1,7 @@ -- DESCRIPTION -- --- This Lua filter for Pandoc converts LaTeX DisplayMath to MathJax generated SVG --- in any of the available MathJax fonts. +-- This Lua filter for Pandoc converts LaTeX DisplayMath to MathJax generated +-- scalable vector graphics (SVG) in any of the available MathJax fonts. -- -- This is useful when a CSS paged media engine cannot process complex JavaScript -- as required by MathJax. From ac2e714efaae38f7101036b25453b3b712aff22e Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 20:38:13 +0200 Subject: [PATCH 05/50] Privacy code auditing new file: .gitignore modified: README.md modified: displaymath2svg.lua --- displaymath2svg/.gitignore | 1 + displaymath2svg/README.md | 7 ++++++- displaymath2svg/displaymath2svg.lua | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 displaymath2svg/.gitignore diff --git a/displaymath2svg/.gitignore b/displaymath2svg/.gitignore new file mode 100644 index 00000000..1377554e --- /dev/null +++ b/displaymath2svg/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index e0e60268..e2b91f94 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -36,7 +36,12 @@ pandoc --mathml --filter='displaymath2svg.lua' # Privacy No Internet connection is established when creating MathJax SVG code using -`tex2svg`. Hence, formulas in SVG can be created offline and remain private. +the `tex2svg` command of [`mathjax-node-cli`](https://github.com/mathjax/mathjax-node-cli). +Hence, formulas in SVG can be created offline and remain private. +For code auditing, see also: + + - + - # Copyright diff --git a/displaymath2svg/displaymath2svg.lua b/displaymath2svg/displaymath2svg.lua index c3e753b9..c168f582 100644 --- a/displaymath2svg/displaymath2svg.lua +++ b/displaymath2svg/displaymath2svg.lua @@ -30,7 +30,13 @@ -- PRIVACY -- -- No Internet connection is established when creating MathJax SVG code using --- tex2svg. Hence, formulas in SVG can be created offline and remain private. +-- the tex2svg command of mathjax-node-cli. +-- Hence, formulas in SVG can be created offline and remain private. +-- +-- For code auditing, see also: +-- - https://github.com/mathjax/MathJax-node +-- - https://github.com/pkra/mathjax-node-sre +-- - https://github.com/mathjax/mathjax-node-cli -- COPYRIGHT From 45b55e32dbe45bc88684f2790a8f9684020b2fe0 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 20:40:38 +0200 Subject: [PATCH 06/50] modified: displaymath2svg README.md --- displaymath2svg/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index e2b91f94..4c6c5f18 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -40,8 +40,8 @@ the `tex2svg` command of [`mathjax-node-cli`](https://github.com/mathjax/mathjax Hence, formulas in SVG can be created offline and remain private. For code auditing, see also: - - - - +- +- # Copyright From a160c060645e19217197ee4103f480c213276c4f Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 20:51:40 +0200 Subject: [PATCH 07/50] modified: README.md modified: displaymath2svg.lua --- displaymath2svg/README.md | 2 +- displaymath2svg/displaymath2svg.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index 4c6c5f18..af2d3f9c 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -37,7 +37,7 @@ pandoc --mathml --filter='displaymath2svg.lua' No Internet connection is established when creating MathJax SVG code using the `tex2svg` command of [`mathjax-node-cli`](https://github.com/mathjax/mathjax-node-cli). -Hence, formulas in SVG can be created offline and remain private. +Hence, formulas in SVG can be created offline and will remain private. For code auditing, see also: - diff --git a/displaymath2svg/displaymath2svg.lua b/displaymath2svg/displaymath2svg.lua index c168f582..48cddc31 100644 --- a/displaymath2svg/displaymath2svg.lua +++ b/displaymath2svg/displaymath2svg.lua @@ -31,7 +31,7 @@ -- -- No Internet connection is established when creating MathJax SVG code using -- the tex2svg command of mathjax-node-cli. --- Hence, formulas in SVG can be created offline and remain private. +-- Hence, formulas in SVG can be created offline and will remain private. -- -- For code auditing, see also: -- - https://github.com/mathjax/MathJax-node From 797a596e02752204d1da3a1d665a4849eb4a4ea8 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 21:31:05 +0200 Subject: [PATCH 08/50] displaymath2svg.lua test added new file: Makefile new file: expected.html new file: sample.md --- displaymath2svg/Makefile | 10 ++++ displaymath2svg/expected.html | 94 +++++++++++++++++++++++++++++++++++ displaymath2svg/sample.md | 9 ++++ 3 files changed, 113 insertions(+) create mode 100644 displaymath2svg/Makefile create mode 100644 displaymath2svg/expected.html create mode 100644 displaymath2svg/sample.md diff --git a/displaymath2svg/Makefile b/displaymath2svg/Makefile new file mode 100644 index 00000000..67518a25 --- /dev/null +++ b/displaymath2svg/Makefile @@ -0,0 +1,10 @@ +DIFF ?= diff --strip-trailing-cr -u + +test: sample.md displaymath2svg.lua + @pandoc --mathml --lua-filter=displaymath2svg.lua --to=html $< \ + | $(DIFF) expected.html - + +expected: sample.md displaymath2svg.lua + pandoc --mathml --lua-filter=displaymath2svg.lua --output=expected.html $< + +.PHONY: test diff --git a/displaymath2svg/expected.html b/displaymath2svg/expected.html new file mode 100644 index 00000000..02674571 --- /dev/null +++ b/displaymath2svg/expected.html @@ -0,0 +1,94 @@ +

Only plane waves in the far field exhibit the characteristic impedance of free space, which is exactly:

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
where:
+c0=299792458msc_0 = 299\,792\,458\,\frac{\text{m}}{\text{s}}: the speed of light in free space
+μ0=4π107Hm\mu_0 = 4\pi\cdot10^{-7}\frac{\text{H}}{\text{m}}: the free space permeability
+ϵ0=1μ0c02\epsilon_0 = \frac{1}{\mu_0 c_0^2}: the absolute permittivity of free space
+Z0Z_0: the characteristic impedance of free space
diff --git a/displaymath2svg/sample.md b/displaymath2svg/sample.md new file mode 100644 index 00000000..540843fe --- /dev/null +++ b/displaymath2svg/sample.md @@ -0,0 +1,9 @@ +Only **plane waves in the far field** exhibit the [characteristic impedance of free space](https://en.wikipedia.org/wiki/Impedance_of_free_space), which is exactly: + +$$Z_0 = \frac{\left|\vec{E}\right|}{\left|\vec{H}\right|} = \sqrt{\frac{\mu_0}{\epsilon_0}} = \mu_0\cdot c_0 \approx 376.73\,\Omega$$ + +| where: +| $c_0 = 299\,792\,458\,\frac{\text{m}}{\text{s}}$: the speed of light in free space +| $\mu_0 = 4\pi\cdot10^{-7}\frac{\text{H}}{\text{m}}$: the free space permeability +| $\epsilon_0 = \frac{1}{\mu_0 c_0^2}$: the absolute permittivity of free space +| $Z_0$: the characteristic impedance of free space From f6d72c9fb036a96ed1c270dfa03ce1d69de2d73a Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 21:41:40 +0200 Subject: [PATCH 09/50] displaymath2svg modified: README.md --- displaymath2svg/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index af2d3f9c..014bccc9 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -5,7 +5,7 @@ for [Pandoc](https://pandoc.org/) converts [LaTeX DisplayMath](https://en.wikibooks.org/wiki/LaTeX/Mathematics) to [MathJax](https://www.mathjax.org/) generated [scalable vector graphics (SVG)](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) -in any of the available [MathJax fonts](https://docs.mathjax.org/en/latest/output/fonts.html). +in any of the [available MathJax fonts](https://docs.mathjax.org/en/latest/output/fonts.html). This is useful when a CSS paged media engine cannot process complex JavaScript as required by MathJax. From 82fa20480fbc32815dd0b95691aeb1405d3fbb89 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sun, 11 Oct 2020 22:40:55 +0200 Subject: [PATCH 10/50] modified: README.md modified: displaymath2svg.lua --- displaymath2svg/README.md | 2 +- displaymath2svg/displaymath2svg.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index 014bccc9..ac6f38a3 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -19,7 +19,7 @@ the imaginary unit j and the exponential function with Euler constant e. # Requires ```bash -$ sudo apt install pandoc pandoc-citeproc libghc-pandoc-prof nodejs npm +$ sudo apt install pandoc nodejs npm $ sudo npm install --global mathjax-node-cli ``` diff --git a/displaymath2svg/displaymath2svg.lua b/displaymath2svg/displaymath2svg.lua index 48cddc31..80589912 100644 --- a/displaymath2svg/displaymath2svg.lua +++ b/displaymath2svg/displaymath2svg.lua @@ -15,7 +15,7 @@ -- REQUIRES -- --- $ sudo apt install pandoc pandoc-citeproc libghc-pandoc-prof nodejs npm +-- $ sudo apt install pandoc nodejs npm -- $ sudo npm install --global mathjax-node-cli From 8db789e6736494af443da8ae4b05908530518107 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 01:01:09 +0200 Subject: [PATCH 11/50] MIT License modified: README.md modified: displaymath2svg.lua --- displaymath2svg/README.md | 34 ++++++++++++-------- displaymath2svg/displaymath2svg.lua | 48 +++++++++++++++++++---------- 2 files changed, 53 insertions(+), 29 deletions(-) diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index ac6f38a3..3565d640 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -12,8 +12,7 @@ as required by MathJax. See: for information about CSS paged media, a [W3C standard](https://www.w3.org/TR/css-page-3/). -This filter also defines the missing LaTeX commands `\j` and `\e{}` for displaying -the imaginary unit j and the exponential function with Euler constant e. +The filter also allows to define additional LaTeX commands. # Requires @@ -27,6 +26,7 @@ $ sudo npm install --global mathjax-node-cli # Usage To be used as a [Pandoc Lua filter](https://pandoc.org/lua-filters.html). +MathML should be chosen as a fallback. ```bash pandoc --mathml --filter='displaymath2svg.lua' @@ -46,20 +46,28 @@ For code auditing, see also: # Copyright -Copyright 2020 Serge Y. Stroobandt +Copyright (c) 2020 Serge Y. Stroobandt -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +## MIT License -You should have received a copy of the GNU General Public License -along with this program. If not, see . +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. # Contact diff --git a/displaymath2svg/displaymath2svg.lua b/displaymath2svg/displaymath2svg.lua index 80589912..3e9d7c1f 100644 --- a/displaymath2svg/displaymath2svg.lua +++ b/displaymath2svg/displaymath2svg.lua @@ -9,8 +9,7 @@ -- See: https://www.print-css.rocks for information about CSS paged media, a W3C -- standard. -- --- This filter also defines the missing LaTeX commands \j and \e{} for displaying --- the imaginary unit j and the exponential function with Euler constant e. +-- The filter also allows to define additional LaTeX commands. -- REQUIRES @@ -22,6 +21,8 @@ -- USAGE -- -- To be used as a Pandoc Lua filter. +-- MathML should be chosen as a fallback. +-- -- pandoc --mathml --filter='displaymath2svg.lua' -- -- See also: https://pandoc.org/lua-filters.html @@ -41,20 +42,27 @@ -- COPYRIGHT -- --- Copyright 2020 Serge Y. Stroobandt +-- Copyright (c) 2020 Serge Y. Stroobandt +-- +-- MIT License -- --- This program is free software: you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation, either version 3 of the License, or --- (at your option) any later version. +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: -- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. -- --- You should have received a copy of the GNU General Public License --- along with this program. If not, see . +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. -- CONTACT @@ -62,12 +70,20 @@ -- $ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d +-- Enter here the full path to the tex2svg binary of mathjax-node-cli. +-- The full path can be found with the following command: +-- $ which tex2svg +local tex2svg = '/usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg' + + -- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html local font = 'Gyre-Pagella' --- Some missing LaTeX math commands are defined here: -local newcommands = '\\newcommand{\\j}{{\\text{j}}}\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}' +-- Any additional LaTeX math commands can be defined here. +-- For example: +-- local newcommands = '\\newcommand{\\j}{{\\text{j}}}\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}' +local newcommands = '' -- The available options for tex2svg are: @@ -84,7 +100,7 @@ local newcommands = '\\newcommand{\\j}{{\\text{j}}}\\newcommand{\\e}[1]{\\,{\\te function Math(elem) if elem.mathtype == 'DisplayMath' then - local svg = pandoc.pipe('/usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg', {'--speech=false', '--font', font, newcommands .. elem.text}, '') + local svg = pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') if FORMAT:match '^html.?' then svg = '
' .. svg .. '
' end From 113413f8462ed22f09bfaa3511e601289f61e6fa Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 01:07:33 +0200 Subject: [PATCH 12/50] MathML comment --- displaymath2svg/README.md | 2 +- displaymath2svg/displaymath2svg.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/displaymath2svg/README.md b/displaymath2svg/README.md index 3565d640..1984a6cc 100644 --- a/displaymath2svg/README.md +++ b/displaymath2svg/README.md @@ -26,7 +26,7 @@ $ sudo npm install --global mathjax-node-cli # Usage To be used as a [Pandoc Lua filter](https://pandoc.org/lua-filters.html). -MathML should be chosen as a fallback. +[MathML](https://en.wikipedia.org/wiki/MathML) should be set as a fallback. ```bash pandoc --mathml --filter='displaymath2svg.lua' diff --git a/displaymath2svg/displaymath2svg.lua b/displaymath2svg/displaymath2svg.lua index 3e9d7c1f..c886027b 100644 --- a/displaymath2svg/displaymath2svg.lua +++ b/displaymath2svg/displaymath2svg.lua @@ -21,7 +21,7 @@ -- USAGE -- -- To be used as a Pandoc Lua filter. --- MathML should be chosen as a fallback. +-- MathML should be set as a fallback. -- -- pandoc --mathml --filter='displaymath2svg.lua' -- From 3102fb56de4b63f028dcc0ebc6edca5b4f1bc3a5 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 02:50:07 +0200 Subject: [PATCH 13/50] math2svg.lua --- displaymath2svg/Makefile | 10 -- displaymath2svg/displaymath2svg.lua | 109 ---------------- {displaymath2svg => math2svg}/.gitignore | 0 math2svg/Makefile | 10 ++ {displaymath2svg => math2svg}/README.md | 4 +- {displaymath2svg => math2svg}/expected.html | 0 math2svg/math2svg.lua | 137 ++++++++++++++++++++ {displaymath2svg => math2svg}/sample.md | 0 8 files changed, 149 insertions(+), 121 deletions(-) delete mode 100644 displaymath2svg/Makefile delete mode 100644 displaymath2svg/displaymath2svg.lua rename {displaymath2svg => math2svg}/.gitignore (100%) create mode 100644 math2svg/Makefile rename {displaymath2svg => math2svg}/README.md (95%) rename {displaymath2svg => math2svg}/expected.html (100%) create mode 100644 math2svg/math2svg.lua rename {displaymath2svg => math2svg}/sample.md (100%) diff --git a/displaymath2svg/Makefile b/displaymath2svg/Makefile deleted file mode 100644 index 67518a25..00000000 --- a/displaymath2svg/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -DIFF ?= diff --strip-trailing-cr -u - -test: sample.md displaymath2svg.lua - @pandoc --mathml --lua-filter=displaymath2svg.lua --to=html $< \ - | $(DIFF) expected.html - - -expected: sample.md displaymath2svg.lua - pandoc --mathml --lua-filter=displaymath2svg.lua --output=expected.html $< - -.PHONY: test diff --git a/displaymath2svg/displaymath2svg.lua b/displaymath2svg/displaymath2svg.lua deleted file mode 100644 index c886027b..00000000 --- a/displaymath2svg/displaymath2svg.lua +++ /dev/null @@ -1,109 +0,0 @@ --- DESCRIPTION --- --- This Lua filter for Pandoc converts LaTeX DisplayMath to MathJax generated --- scalable vector graphics (SVG) in any of the available MathJax fonts. --- --- This is useful when a CSS paged media engine cannot process complex JavaScript --- as required by MathJax. --- --- See: https://www.print-css.rocks for information about CSS paged media, a W3C --- standard. --- --- The filter also allows to define additional LaTeX commands. - - --- REQUIRES --- --- $ sudo apt install pandoc nodejs npm --- $ sudo npm install --global mathjax-node-cli - - --- USAGE --- --- To be used as a Pandoc Lua filter. --- MathML should be set as a fallback. --- --- pandoc --mathml --filter='displaymath2svg.lua' --- --- See also: https://pandoc.org/lua-filters.html - - --- PRIVACY --- --- No Internet connection is established when creating MathJax SVG code using --- the tex2svg command of mathjax-node-cli. --- Hence, formulas in SVG can be created offline and will remain private. --- --- For code auditing, see also: --- - https://github.com/mathjax/MathJax-node --- - https://github.com/pkra/mathjax-node-sre --- - https://github.com/mathjax/mathjax-node-cli - - --- COPYRIGHT --- --- Copyright (c) 2020 Serge Y. Stroobandt --- --- MIT License --- --- Permission is hereby granted, free of charge, to any person obtaining a copy --- of this software and associated documentation files (the "Software"), to deal --- in the Software without restriction, including without limitation the rights --- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --- copies of the Software, and to permit persons to whom the Software is --- furnished to do so, subject to the following conditions: --- --- The above copyright notice and this permission notice shall be included in all --- copies or substantial portions of the Software. --- --- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --- SOFTWARE. - - --- CONTACT --- --- $ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d - - --- Enter here the full path to the tex2svg binary of mathjax-node-cli. --- The full path can be found with the following command: --- $ which tex2svg -local tex2svg = '/usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg' - - --- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html -local font = 'Gyre-Pagella' - - --- Any additional LaTeX math commands can be defined here. --- For example: --- local newcommands = '\\newcommand{\\j}{{\\text{j}}}\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}' -local newcommands = '' - - --- The available options for tex2svg are: - --help Show help [boolean] - --version Show version number [boolean] - --inline process as in-line TeX [boolean] - --speech include speech text [boolean] [default: true] - --linebreaks perform automatic line-breaking [boolean] - --font web font to use [default: "TeX"] - --ex ex-size in pixels [default: 6] - --width width of container in ex [default: 100] - --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] - - -function Math(elem) - if elem.mathtype == 'DisplayMath' then - local svg = pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') - if FORMAT:match '^html.?' then - svg = '
' .. svg .. '
' - end - return pandoc.RawInline(FORMAT, svg) - end -end diff --git a/displaymath2svg/.gitignore b/math2svg/.gitignore similarity index 100% rename from displaymath2svg/.gitignore rename to math2svg/.gitignore diff --git a/math2svg/Makefile b/math2svg/Makefile new file mode 100644 index 00000000..b73475e2 --- /dev/null +++ b/math2svg/Makefile @@ -0,0 +1,10 @@ +DIFF ?= diff --strip-trailing-cr -u + +test: sample.md math2svg.lua + @pandoc --mathml --lua-filter=math2svg.lua --to=html $< \ + | $(DIFF) expected.html - + +expected: sample.md math2svg.lua + pandoc --mathml --lua-filter=math2svg.lua --output=expected.html $< + +.PHONY: test diff --git a/displaymath2svg/README.md b/math2svg/README.md similarity index 95% rename from displaymath2svg/README.md rename to math2svg/README.md index 1984a6cc..b9eb3446 100644 --- a/displaymath2svg/README.md +++ b/math2svg/README.md @@ -2,7 +2,7 @@ This [Lua filter](https://pandoc.org/lua-filters.html) for [Pandoc](https://pandoc.org/) -converts [LaTeX DisplayMath](https://en.wikibooks.org/wiki/LaTeX/Mathematics) +converts [LaTeX math](https://en.wikibooks.org/wiki/LaTeX/Mathematics) to [MathJax](https://www.mathjax.org/) generated [scalable vector graphics (SVG)](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) in any of the [available MathJax fonts](https://docs.mathjax.org/en/latest/output/fonts.html). @@ -29,7 +29,7 @@ To be used as a [Pandoc Lua filter](https://pandoc.org/lua-filters.html). [MathML](https://en.wikipedia.org/wiki/MathML) should be set as a fallback. ```bash -pandoc --mathml --filter='displaymath2svg.lua' +pandoc --mathml --filter='math2svg.lua' ``` diff --git a/displaymath2svg/expected.html b/math2svg/expected.html similarity index 100% rename from displaymath2svg/expected.html rename to math2svg/expected.html diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua new file mode 100644 index 00000000..07659647 --- /dev/null +++ b/math2svg/math2svg.lua @@ -0,0 +1,137 @@ +-- DESCRIPTION +-- +-- This Lua filter for Pandoc converts LaTeX math to MathJax generated +-- scalable vector graphics (SVG) in any of the available MathJax fonts. +-- +-- This is useful when a CSS paged media engine cannot process complex JavaScript +-- as required by MathJax. +-- +-- See: https://www.print-css.rocks for information about CSS paged media, a W3C +-- standard. +-- +-- The filter also allows to define additional LaTeX commands. + + +-- REQUIRES +-- +-- $ sudo apt install pandoc nodejs npm +-- $ sudo npm install --global mathjax-node-cli + + +-- USAGE +-- +-- To be used as a Pandoc Lua filter. +-- MathML should be set as a fallback. +-- +-- pandoc --mathml --filter='math2svg.lua' +-- +-- See also: https://pandoc.org/lua-filters.html + + +-- PRIVACY +-- +-- No Internet connection is established when creating MathJax SVG code using +-- the tex2svg command of mathjax-node-cli. +-- Hence, formulas in SVG can be created offline and will remain private. +-- +-- For code auditing, see also: +-- - https://github.com/mathjax/MathJax-node +-- - https://github.com/pkra/mathjax-node-sre +-- - https://github.com/mathjax/mathjax-node-cli + + +-- COPYRIGHT +-- +-- Copyright (c) 2020 Serge Y. Stroobandt +-- +-- MIT License +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. + + +-- CONTACT +-- +-- $ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d + + +-- Enter here the full path to the tex2svg binary of mathjax-node-cli. +-- The full path can be found with the following command: +-- $ which tex2svg +local tex2svg = '/usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg' + + +-- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html +local font = 'Gyre-Pagella' + + +-- Indicate with true or false whether DisplayMath and InlineMath should be converted to SVG. +local display2svg = true +local inline2svg = false +-- The fallback is MathML if pandoc is executed with the --mathml argument. +-- MathML output gets generated much faster than SVG output. +-- Moreover, MathML is better suited to InlineMath as line heights are kept small. + + +-- Any additional LaTeX math commands can be defined here. +-- For example: +-- local newcommands = '\\newcommand{\\j}{{\\text{j}}}\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}' +local newcommands = '' + + +-- The available options for tex2svg are: + --help Show help [boolean] + --version Show version number [boolean] + --inline process as in-line TeX [boolean] + --speech include speech text [boolean] [default: true] + --linebreaks perform automatic line-breaking [boolean] + --font web font to use [default: "TeX"] + --ex ex-size in pixels [default: 6] + --width width of container in ex [default: 100] + --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] + + +function Math(elem) + + if elem.mathtype == 'DisplayMath' and display2svg then + + local svg = pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') + + if FORMAT:match '^html.?' then + svg = '
' .. svg .. '
' + return pandoc.RawInline(FORMAT, svg) + else + local filename = pandoc.sha1(svg) .. '.svg' + return pandoc.mediabag.insert(filename, 'image/svg+xml', svg) + end + + elseif elem.mathtype == 'InlineMath' and inline2svg then + + local svg = pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') + + if FORMAT:match '^html.?' then + svg = '' .. svg .. '' + return pandoc.RawInline(FORMAT, svg) + else + local filename = pandoc.sha1(svg) .. '.svg' + return pandoc.mediabag.insert(filename, 'image/svg+xml', svg) + end + + end + +end diff --git a/displaymath2svg/sample.md b/math2svg/sample.md similarity index 100% rename from displaymath2svg/sample.md rename to math2svg/sample.md From 1f96b0d5c7895dbef3d3e193f427c2cc16951c48 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 14:23:11 +0200 Subject: [PATCH 14/50] README.md deleted: .gitignore modified: README.md modified: math2svg.lua --- math2svg/.gitignore | 1 - math2svg/README.md | 20 +++++++++++--------- math2svg/math2svg.lua | 30 +++++++++++++++--------------- 3 files changed, 26 insertions(+), 25 deletions(-) delete mode 100644 math2svg/.gitignore diff --git a/math2svg/.gitignore b/math2svg/.gitignore deleted file mode 100644 index 1377554e..00000000 --- a/math2svg/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.swp diff --git a/math2svg/README.md b/math2svg/README.md index b9eb3446..fef130ae 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -1,4 +1,7 @@ -# Description +# math2svg + + +## Description This [Lua filter](https://pandoc.org/lua-filters.html) for [Pandoc](https://pandoc.org/) @@ -12,10 +15,10 @@ as required by MathJax. See: for information about CSS paged media, a [W3C standard](https://www.w3.org/TR/css-page-3/). -The filter also allows to define additional LaTeX commands. +No Internet connection is required for SVG conversions, resulting in absolute privacy. -# Requires +## Requires ```bash $ sudo apt install pandoc nodejs npm @@ -23,7 +26,7 @@ $ sudo npm install --global mathjax-node-cli ``` -# Usage +## Usage To be used as a [Pandoc Lua filter](https://pandoc.org/lua-filters.html). [MathML](https://en.wikipedia.org/wiki/MathML) should be set as a fallback. @@ -33,7 +36,7 @@ pandoc --mathml --filter='math2svg.lua' ``` -# Privacy +## Privacy No Internet connection is established when creating MathJax SVG code using the `tex2svg` command of [`mathjax-node-cli`](https://github.com/mathjax/mathjax-node-cli). @@ -44,12 +47,11 @@ For code auditing, see also: - -# Copyright +## Copyright & License Copyright (c) 2020 Serge Y. Stroobandt - -## MIT License +MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -70,7 +72,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# Contact +## Contact ```bash $ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 07659647..9fb709f5 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -4,12 +4,11 @@ -- scalable vector graphics (SVG) in any of the available MathJax fonts. -- -- This is useful when a CSS paged media engine cannot process complex JavaScript --- as required by MathJax. +-- as required by MathJax. See: https://www.print-css.rocks for information about +-- CSS paged media, a W3C standard. -- --- See: https://www.print-css.rocks for information about CSS paged media, a W3C --- standard. --- --- The filter also allows to define additional LaTeX commands. +-- No Internet connection is required for SVG conversions, resulting in absolute +-- privacy. -- REQUIRES @@ -88,12 +87,6 @@ local inline2svg = false -- Moreover, MathML is better suited to InlineMath as line heights are kept small. --- Any additional LaTeX math commands can be defined here. --- For example: --- local newcommands = '\\newcommand{\\j}{{\\text{j}}}\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}' -local newcommands = '' - - -- The available options for tex2svg are: --help Show help [boolean] --version Show version number [boolean] @@ -106,30 +99,37 @@ local newcommands = '' --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] +local function convert(elem) + return pandoc.pipe(tex2svg, {'--speech=false', '--font', font, elem.text}, '') +end + + function Math(elem) if elem.mathtype == 'DisplayMath' and display2svg then - local svg = pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') + local svg = convert(elem) if FORMAT:match '^html.?' then svg = '
' .. svg .. '
' return pandoc.RawInline(FORMAT, svg) else local filename = pandoc.sha1(svg) .. '.svg' - return pandoc.mediabag.insert(filename, 'image/svg+xml', svg) + pandoc.mediabag.insert(filename, 'image/svg+xml', svg) + return end elseif elem.mathtype == 'InlineMath' and inline2svg then - local svg = pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') + local svg = convert(elem) if FORMAT:match '^html.?' then svg = '' .. svg .. '' return pandoc.RawInline(FORMAT, svg) else local filename = pandoc.sha1(svg) .. '.svg' - return pandoc.mediabag.insert(filename, 'image/svg+xml', svg) + pandoc.mediabag.insert(filename, 'image/svg+xml', svg) + return end end From 6848665159089338f1aad04d394b301f68ff0a02 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 14:54:20 +0200 Subject: [PATCH 15/50] refactoring of math2svg.lua --- math2svg/math2svg.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 9fb709f5..abe75017 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -106,30 +106,30 @@ end function Math(elem) - if elem.mathtype == 'DisplayMath' and display2svg then - - local svg = convert(elem) + local svg = nil + local tags = nil - if FORMAT:match '^html.?' then - svg = '
' .. svg .. '
' - return pandoc.RawInline(FORMAT, svg) - else - local filename = pandoc.sha1(svg) .. '.svg' - pandoc.mediabag.insert(filename, 'image/svg+xml', svg) - return - end + if elem.mathtype == 'DisplayMath' and display2svg then + svg = convert(elem) + tags = {'
', '
'} elseif elem.mathtype == 'InlineMath' and inline2svg then + svg = convert(elem) + tags = {'', ''} - local svg = convert(elem) + end + + if svg then if FORMAT:match '^html.?' then - svg = '' .. svg .. '' + svg = tags[1] .. svg .. tags[2] return pandoc.RawInline(FORMAT, svg) + else local filename = pandoc.sha1(svg) .. '.svg' pandoc.mediabag.insert(filename, 'image/svg+xml', svg) return + end end From 2121998635257f3dd52d0a86686debfd1c13e526 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 15:06:14 +0200 Subject: [PATCH 16/50] pandoc.Image when output format is not HTML. modified: math2svg.lua --- math2svg/math2svg.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index abe75017..101a29e4 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -128,7 +128,7 @@ function Math(elem) else local filename = pandoc.sha1(svg) .. '.svg' pandoc.mediabag.insert(filename, 'image/svg+xml', svg) - return + return pandoc.Image('', filename) end From 277c00733543b7fedfde05507a7d803d2b59b430 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 15:18:42 +0200 Subject: [PATCH 17/50] License --- math2svg/README.md | 2 +- math2svg/math2svg.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index fef130ae..065a8fc5 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -47,7 +47,7 @@ For code auditing, see also: - -## Copyright & License +## License Copyright (c) 2020 Serge Y. Stroobandt diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 101a29e4..6960ae37 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -39,7 +39,7 @@ -- - https://github.com/mathjax/mathjax-node-cli --- COPYRIGHT +-- LICENSE -- -- Copyright (c) 2020 Serge Y. Stroobandt -- From 74a44450d4312c24b95775296d501ff0ba62ad4a Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 17:43:54 +0200 Subject: [PATCH 18/50] install instructions --- math2svg/README.md | 17 ++++++++++++++++- math2svg/math2svg.lua | 21 +++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index 065a8fc5..95975ada 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -18,11 +18,26 @@ a [W3C standard](https://www.w3.org/TR/css-page-3/). No Internet connection is required for SVG conversions, resulting in absolute privacy. -## Requires +## Requirements + +First, use the package manager of your operating system to install +`pandoc`, `nodejs` and `npm`. `brew` and `choco` are recommended package mangers for +respectively macOS and Windows. See: ```bash $ sudo apt install pandoc nodejs npm +$ sudo dnf install pandoc nodejs npm +$ sudo yum install pandoc nodejs npm +$ brew install pandoc nodejs npm +> choco install pandoc nodejs npm +``` + +Then, install `mathjax-node-cli` using `npm`. +Leave out the `sudo` on Windows. + +```bash $ sudo npm install --global mathjax-node-cli +> npm install --global mathjax-node-cli ``` diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 6960ae37..9170338d 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -11,10 +11,23 @@ -- privacy. --- REQUIRES +-- REQUIREMENTS -- --- $ sudo apt install pandoc nodejs npm --- $ sudo npm install --global mathjax-node-cli +-- First, use the package manager of your operating system to install +-- pandoc, nodejs and npm. `brew` and `choco` are recommended package mangers for +-- respectively macOS and Windows. See: +-- +-- $ sudo apt install pandoc nodejs npm +-- $ sudo dnf install pandoc nodejs npm +-- $ sudo yum install pandoc nodejs npm +-- $ brew install pandoc nodejs npm +-- > choco install pandoc nodejs npm +-- +-- Then, install mathjax-node-cli using npm. +-- Leave out the sudo on Windows. +-- +-- $ sudo npm install --global mathjax-node-cli +-- > npm install --global mathjax-node-cli -- USAGE @@ -22,7 +35,7 @@ -- To be used as a Pandoc Lua filter. -- MathML should be set as a fallback. -- --- pandoc --mathml --filter='math2svg.lua' +-- pandoc --mathml --filter='math2svg.lua' -- -- See also: https://pandoc.org/lua-filters.html From afdfe46b9e230ec8712ef89b9b09cec1494dc42b Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 19:29:58 +0200 Subject: [PATCH 19/50] MathML newcommands --- math2svg/expected.html | 89 +++++++++++++++++++++++++++++++++++++++--- math2svg/math2svg.lua | 38 +++++++++++------- math2svg/sample.md | 13 +++++- 3 files changed, 119 insertions(+), 21 deletions(-) diff --git a/math2svg/expected.html b/math2svg/expected.html index 02674571..6e5bc763 100644 --- a/math2svg/expected.html +++ b/math2svg/expected.html @@ -1,4 +1,4 @@ -

Only plane waves in the far field exhibit the characteristic impedance of free space, which is exactly:

+

Only plane waves in the far field exhibit the characteristic impedance of free space, which is exactly:

@@ -88,7 +88,86 @@

where:
-c0=299792458msc_0 = 299\,792\,458\,\frac{\text{m}}{\text{s}}: the speed of light in free space
-μ0=4π107Hm\mu_0 = 4\pi\cdot10^{-7}\frac{\text{H}}{\text{m}}: the free space permeability
-ϵ0=1μ0c02\epsilon_0 = \frac{1}{\mu_0 c_0^2}: the absolute permittivity of free space
-Z0Z_0: the characteristic impedance of free space
+c0=299792458ms\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}c_0 = 299\,792\,458\,\frac{\text{m}}{\text{s}}: the speed of light in free space
+μ0=4π107Hm\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\mu_0 = 4\pi\cdot10^{-7}\frac{\text{H}}{\text{m}}: the free space permeability
+ϵ0=1μ0c02\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\epsilon_0 = \frac{1}{\mu_0 c_0^2}: the absolute permittivity of free space
+Z0\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}Z_0: the characteristic impedance of free space +
+

The input impedance Zin,short\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}Z_\text{in,$\,$short} of a transmission line stub terminated in a short circuit is given by:

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
where:
+γ=α+jβ\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\gamma = \alpha + \j\beta is the propagation constant γ\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\gamma,
+α\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\alpha is the attenuation constant, and
+β\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\beta is the phase constant.
diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 9170338d..e2753805 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -100,20 +100,28 @@ local inline2svg = false -- Moreover, MathML is better suited to InlineMath as line heights are kept small. --- The available options for tex2svg are: - --help Show help [boolean] - --version Show version number [boolean] - --inline process as in-line TeX [boolean] - --speech include speech text [boolean] [default: true] - --linebreaks perform automatic line-breaking [boolean] - --font web font to use [default: "TeX"] - --ex ex-size in pixels [default: 6] - --width width of container in ex [default: 100] - --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] +-- Both MathML and the version of MathJax included with mathjax-node-cli +-- lack a number of LaTeX math commands that are available with the newest online versions. +-- These missing LaTeX math commands are defined here. +local missing = {'\\newcommand{\\j}{{\\text{j}}}', '\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}'} +local newcommands = '' +for i = 1, #missing do + newcommands = newcommands .. missing[i] +end local function convert(elem) - return pandoc.pipe(tex2svg, {'--speech=false', '--font', font, elem.text}, '') +-- The available options for tex2svg are: + --help Show help [boolean] + --version Show version number [boolean] + --inline process as in-line TeX [boolean] + --speech include speech text [boolean] [default: true] + --linebreaks perform automatic line-breaking [boolean] + --font web font to use [default: "TeX"] + --ex ex-size in pixels [default: 6] + --width width of container in ex [default: 100] + --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] + return pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') end @@ -125,11 +133,9 @@ function Math(elem) if elem.mathtype == 'DisplayMath' and display2svg then svg = convert(elem) tags = {'
', '
'} - elseif elem.mathtype == 'InlineMath' and inline2svg then svg = convert(elem) tags = {'', ''} - end if svg then @@ -137,14 +143,16 @@ function Math(elem) if FORMAT:match '^html.?' then svg = tags[1] .. svg .. tags[2] return pandoc.RawInline(FORMAT, svg) - else local filename = pandoc.sha1(svg) .. '.svg' pandoc.mediabag.insert(filename, 'image/svg+xml', svg) return pandoc.Image('', filename) - end + else + elem.text = newcommands .. elem.text + return elem + end end diff --git a/math2svg/sample.md b/math2svg/sample.md index 540843fe..5687af7e 100644 --- a/math2svg/sample.md +++ b/math2svg/sample.md @@ -1,4 +1,4 @@ -Only **plane waves in the far field** exhibit the [characteristic impedance of free space](https://en.wikipedia.org/wiki/Impedance_of_free_space), which is exactly: +Only plane waves in the far field exhibit the [characteristic impedance of free space](https://en.wikipedia.org/wiki/Impedance_of_free_space), which is exactly: $$Z_0 = \frac{\left|\vec{E}\right|}{\left|\vec{H}\right|} = \sqrt{\frac{\mu_0}{\epsilon_0}} = \mu_0\cdot c_0 \approx 376.73\,\Omega$$ @@ -7,3 +7,14 @@ $$Z_0 = \frac{\left|\vec{E}\right|}{\left|\vec{H}\right|} = \sqrt{\frac{\mu_0}{\ | $\mu_0 = 4\pi\cdot10^{-7}\frac{\text{H}}{\text{m}}$: the free space permeability | $\epsilon_0 = \frac{1}{\mu_0 c_0^2}$: the absolute permittivity of free space | $Z_0$: the characteristic impedance of free space + +--- + +The input impedance $Z_\text{in,$\,$short}$ of a transmission line stub terminated in a short circuit is given by: + +$$Z_\text{in,$\,$short} = Z_\text{c} \tanh{(\gamma\ell)} \approx \j\tan{(\beta\ell)}\,Z_\text{c}$$ + +| where: +| $\gamma = \alpha + \j\beta$ is the [propagation constant $\gamma$](https://en.wikipedia.org/wiki/Propagation_constant#Definition), +| $\alpha$ is the attenuation constant, and +| $\beta$ is the [phase constant](https://en.wikipedia.org/wiki/Propagation_constant#Phase_constant). From 1516ed517bef5c5ce3206b49758a4e023cf08f04 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 12 Oct 2020 22:31:47 +0200 Subject: [PATCH 20/50] improved inline SVG --- math2svg/math2svg.lua | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index e2753805..23d0ff3a 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -97,7 +97,7 @@ local display2svg = true local inline2svg = false -- The fallback is MathML if pandoc is executed with the --mathml argument. -- MathML output gets generated much faster than SVG output. --- Moreover, MathML is better suited to InlineMath as line heights are kept small. +-- Moreover, MathML is well suited to InlineMath as line heights are kept small. -- Both MathML and the version of MathJax included with mathjax-node-cli @@ -110,38 +110,36 @@ for i = 1, #missing do end -local function convert(elem) --- The available options for tex2svg are: - --help Show help [boolean] - --version Show version number [boolean] - --inline process as in-line TeX [boolean] - --speech include speech text [boolean] [default: true] - --linebreaks perform automatic line-breaking [boolean] - --font web font to use [default: "TeX"] - --ex ex-size in pixels [default: 6] - --width width of container in ex [default: 100] - --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] - return pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') -end - - function Math(elem) local svg = nil local tags = nil if elem.mathtype == 'DisplayMath' and display2svg then - svg = convert(elem) + svg = pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') tags = {'
', '
'} + elseif elem.mathtype == 'InlineMath' and inline2svg then - svg = convert(elem) + svg = pandoc.pipe(tex2svg, {'--inline', '--speech=false', '--font', font, newcommands .. elem.text}, '') tags = {'', ''} + end +-- The available options for tex2svg are: + --help Show help [boolean] + --version Show version number [boolean] + --inline process as in-line TeX [boolean] + --speech include speech text [boolean] [default: true] + --linebreaks perform automatic line-breaking [boolean] + --font web font to use [default: "TeX"] + --ex ex-size in pixels [default: 6] + --width width of container in ex [default: 100] + --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] + if svg then if FORMAT:match '^html.?' then - svg = tags[1] .. svg .. tags[2] + svg = tags[1] .. svg .. tags[2] return pandoc.RawInline(FORMAT, svg) else local filename = pandoc.sha1(svg) .. '.svg' From fbdf9cecb05f1ee7781e7b772b4bce15175e7438 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Tue, 13 Oct 2020 02:02:39 +0200 Subject: [PATCH 21/50] argumentlist & reduced description --- math2svg/math2svg.lua | 128 ++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 74 deletions(-) diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 23d0ff3a..e32dbd11 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -2,54 +2,13 @@ -- -- This Lua filter for Pandoc converts LaTeX math to MathJax generated -- scalable vector graphics (SVG) in any of the available MathJax fonts. --- --- This is useful when a CSS paged media engine cannot process complex JavaScript --- as required by MathJax. See: https://www.print-css.rocks for information about --- CSS paged media, a W3C standard. --- --- No Internet connection is required for SVG conversions, resulting in absolute --- privacy. +-- This is useful when a CSS paged media engine cannot process complex JavaScript. +-- No Internet connection is required for SVG conversions, resulting in absolute privacy. --- REQUIREMENTS --- --- First, use the package manager of your operating system to install --- pandoc, nodejs and npm. `brew` and `choco` are recommended package mangers for --- respectively macOS and Windows. See: +-- REQUIREMENTS, USAGE & PRIVACY -- --- $ sudo apt install pandoc nodejs npm --- $ sudo dnf install pandoc nodejs npm --- $ sudo yum install pandoc nodejs npm --- $ brew install pandoc nodejs npm --- > choco install pandoc nodejs npm --- --- Then, install mathjax-node-cli using npm. --- Leave out the sudo on Windows. --- --- $ sudo npm install --global mathjax-node-cli --- > npm install --global mathjax-node-cli - - --- USAGE --- --- To be used as a Pandoc Lua filter. --- MathML should be set as a fallback. --- --- pandoc --mathml --filter='math2svg.lua' --- --- See also: https://pandoc.org/lua-filters.html - - --- PRIVACY --- --- No Internet connection is established when creating MathJax SVG code using --- the tex2svg command of mathjax-node-cli. --- Hence, formulas in SVG can be created offline and will remain private. --- --- For code auditing, see also: --- - https://github.com/mathjax/MathJax-node --- - https://github.com/pkra/mathjax-node-sre --- - https://github.com/mathjax/mathjax-node-cli +-- See: https://github.com/pandoc/lua-filters/tree/master/math2svg -- LICENSE @@ -82,31 +41,50 @@ -- $ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d --- Enter here the full path to the tex2svg binary of mathjax-node-cli. --- The full path can be found with the following command: --- $ which tex2svg -local tex2svg = '/usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg' - - --- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html -local font = 'Gyre-Pagella' - - -- Indicate with true or false whether DisplayMath and InlineMath should be converted to SVG. local display2svg = true local inline2svg = false -- The fallback is MathML if pandoc is executed with the --mathml argument. -- MathML output gets generated much faster than SVG output. --- Moreover, MathML is well suited to InlineMath as line heights are kept small. +-- Moreover, MathML is well suited for InlineMath as line heights are kept small. --- Both MathML and the version of MathJax included with mathjax-node-cli --- lack a number of LaTeX math commands that are available with the newest online versions. --- These missing LaTeX math commands are defined here. -local missing = {'\\newcommand{\\j}{{\\text{j}}}', '\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}'} -local newcommands = '' -for i = 1, #missing do - newcommands = newcommands .. missing[i] +-- Enter here the full path to the tex2svg binary of mathjax-node-cli. +-- The full path can be found with one of the following commands: +-- $ which -a tex2svg +-- > where tex2svg +local tex2svg = '/usr/local/bin/tex2svg' + +-- Speech text inclusion +local speech = false +speech = tostring(speech) + +-- Automatic line breaking +local linebreaks = true +linebreaks = tostring(linebreaks) + +-- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html +local font = 'TeX' +font = 'Gyre-Pagella' + +-- ex size in pixels +local ex = 6 +ex = tostring(ex) + +-- container width in ex +local width = 100 +width = tostring(width) + +-- String of extensions to be loaded at run time +-- Available extensions are at: /usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/ +local extensions = '' + +-- MathJax only processes macros in math mode. +-- https://docs.mathjax.org/en/latest/input/tex/macros.html +local macrolist = {'\\newcommand{\\j}{{\\text{j}}}', '\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}'} +local macros = '' +for i = 1, #macrolist do + macros = macros .. macrolist[i] end @@ -114,16 +92,7 @@ function Math(elem) local svg = nil local tags = nil - - if elem.mathtype == 'DisplayMath' and display2svg then - svg = pandoc.pipe(tex2svg, {'--speech=false', '--font', font, newcommands .. elem.text}, '') - tags = {'
', '
'} - - elseif elem.mathtype == 'InlineMath' and inline2svg then - svg = pandoc.pipe(tex2svg, {'--inline', '--speech=false', '--font', font, newcommands .. elem.text}, '') - tags = {'', ''} - - end + local argumentlist = {'--speech', speech, '--linebreaks', linebreaks, '--font', font, '--ex', ex, '--width', width, '--extensions', extensions, macros .. elem.text} -- The available options for tex2svg are: --help Show help [boolean] @@ -136,6 +105,17 @@ function Math(elem) --width width of container in ex [default: 100] --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] + if elem.mathtype == 'DisplayMath' and display2svg then + svg = pandoc.pipe(tex2svg, argumentlist, '') + tags = {'
', '
'} + + elseif elem.mathtype == 'InlineMath' and inline2svg then + table.insert(argumentlist, 1, '--inline') + svg = pandoc.pipe(tex2svg, argumentlist, '') + tags = {'', ''} + + end + if svg then if FORMAT:match '^html.?' then @@ -148,7 +128,7 @@ function Math(elem) end else - elem.text = newcommands .. elem.text + elem.text = macros .. elem.text return elem end From a38c802f7e5bb8ba1cec335e6dd3066d18d7bd87 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Tue, 13 Oct 2020 02:56:26 +0200 Subject: [PATCH 22/50] macros removed in favour of header-includes --- math2svg/expected.html | 65 ++++++++++++++++++++++++++++++++++++------ math2svg/math2svg.lua | 14 ++------- math2svg/sample.md | 12 ++++++++ 3 files changed, 72 insertions(+), 19 deletions(-) diff --git a/math2svg/expected.html b/math2svg/expected.html index 6e5bc763..638f1cbb 100644 --- a/math2svg/expected.html +++ b/math2svg/expected.html @@ -88,12 +88,61 @@

where:
-c0=299792458ms\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}c_0 = 299\,792\,458\,\frac{\text{m}}{\text{s}}: the speed of light in free space
-μ0=4π107Hm\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\mu_0 = 4\pi\cdot10^{-7}\frac{\text{H}}{\text{m}}: the free space permeability
-ϵ0=1μ0c02\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\epsilon_0 = \frac{1}{\mu_0 c_0^2}: the absolute permittivity of free space
-Z0\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}Z_0: the characteristic impedance of free space
+c0=299792458msc_0 = 299\,792\,458\,\frac{\text{m}}{\text{s}}: the speed of light in free space
+μ0=4π107Hm\mu_0 = 4\pi\cdot10^{-7}\frac{\text{H}}{\text{m}}: the free space permeability
+ϵ0=1μ0c02\epsilon_0 = \frac{1}{\mu_0 c_0^2}: the absolute permittivity of free space
+Z0Z_0: the characteristic impedance of free space
-

The input impedance Zin,short\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}Z_\text{in,$\,$short} of a transmission line stub terminated in a short circuit is given by:

+

Euler’s formula:

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+

The input impedance Zin,shortZ_\text{in,$\,$short} of a transmission line stub terminated in a short circuit is given by:

@@ -168,6 +217,6 @@

where:
-γ=α+jβ\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\gamma = \alpha + \j\beta is the propagation constant γ\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\gamma,
-α\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\alpha is the attenuation constant, and
-β\newcommand{\j}{{\text{j}}}\newcommand{\e}[1]{\,{\text{e}}^{#1}}\beta is the phase constant.
+γ=α+jβ\gamma = \alpha + {\text{j}}\beta is the propagation constant γ\gamma,
+α\alpha is the attenuation constant, and
+β\beta is the phase constant. diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index e32dbd11..875915aa 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -50,11 +50,12 @@ local inline2svg = false -- Enter here the full path to the tex2svg binary of mathjax-node-cli. --- The full path can be found with one of the following commands: +-- The full path can be found with the following command on *nix, respectively Windows: -- $ which -a tex2svg -- > where tex2svg local tex2svg = '/usr/local/bin/tex2svg' + -- Speech text inclusion local speech = false speech = tostring(speech) @@ -79,20 +80,12 @@ width = tostring(width) -- Available extensions are at: /usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/ local extensions = '' --- MathJax only processes macros in math mode. --- https://docs.mathjax.org/en/latest/input/tex/macros.html -local macrolist = {'\\newcommand{\\j}{{\\text{j}}}', '\\newcommand{\\e}[1]{\\,{\\text{e}}^{#1}}'} -local macros = '' -for i = 1, #macrolist do - macros = macros .. macrolist[i] -end - function Math(elem) local svg = nil local tags = nil - local argumentlist = {'--speech', speech, '--linebreaks', linebreaks, '--font', font, '--ex', ex, '--width', width, '--extensions', extensions, macros .. elem.text} + local argumentlist = {'--speech', speech, '--linebreaks', linebreaks, '--font', font, '--ex', ex, '--width', width, '--extensions', extensions, elem.text} -- The available options for tex2svg are: --help Show help [boolean] @@ -128,7 +121,6 @@ function Math(elem) end else - elem.text = macros .. elem.text return elem end diff --git a/math2svg/sample.md b/math2svg/sample.md index 5687af7e..9c24d609 100644 --- a/math2svg/sample.md +++ b/math2svg/sample.md @@ -1,3 +1,9 @@ +--- +header-includes: + - '\newcommand{\j}{{\text{j}}}' + - '\newcommand{\e}[1]{\,{\text{e}}^{#1}}' +--- + Only plane waves in the far field exhibit the [characteristic impedance of free space](https://en.wikipedia.org/wiki/Impedance_of_free_space), which is exactly: $$Z_0 = \frac{\left|\vec{E}\right|}{\left|\vec{H}\right|} = \sqrt{\frac{\mu_0}{\epsilon_0}} = \mu_0\cdot c_0 \approx 376.73\,\Omega$$ @@ -10,6 +16,12 @@ $$Z_0 = \frac{\left|\vec{E}\right|}{\left|\vec{H}\right|} = \sqrt{\frac{\mu_0}{\ --- +Euler's formula: + +$$\e{\j\omega t} = \cos{\omega t} + \j \sin{\omega t}$$ + +--- + The input impedance $Z_\text{in,$\,$short}$ of a transmission line stub terminated in a short circuit is given by: $$Z_\text{in,$\,$short} = Z_\text{c} \tanh{(\gamma\ell)} \approx \j\tan{(\beta\ell)}\,Z_\text{c}$$ From dd19ae1d25a3bcf4417ba3f8efb92abbfb50db6f Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Tue, 13 Oct 2020 23:45:13 +0200 Subject: [PATCH 23/50] sample.yaml --- math2svg/Makefile | 4 ++-- math2svg/expected.html | 2 +- math2svg/sample.md | 6 ------ math2svg/sample.yaml | 5 +++++ 4 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 math2svg/sample.yaml diff --git a/math2svg/Makefile b/math2svg/Makefile index b73475e2..288aed91 100644 --- a/math2svg/Makefile +++ b/math2svg/Makefile @@ -1,10 +1,10 @@ DIFF ?= diff --strip-trailing-cr -u test: sample.md math2svg.lua - @pandoc --mathml --lua-filter=math2svg.lua --to=html $< \ + @pandoc --mathml --lua-filter=math2svg.lua --to=html sample.yaml $< \ | $(DIFF) expected.html - expected: sample.md math2svg.lua - pandoc --mathml --lua-filter=math2svg.lua --output=expected.html $< + pandoc --mathml --lua-filter=math2svg.lua --output=expected.html sample.yaml $< .PHONY: test diff --git a/math2svg/expected.html b/math2svg/expected.html index 638f1cbb..d889ad96 100644 --- a/math2svg/expected.html +++ b/math2svg/expected.html @@ -217,6 +217,6 @@

where:
-γ=α+jβ\gamma = \alpha + {\text{j}}\beta is the propagation constant γ\gamma,
+γ=α+jβ\gamma = \alpha + \text{j}\beta is the propagation constant γ\gamma,
α\alpha is the attenuation constant, and
β\beta is the phase constant.
diff --git a/math2svg/sample.md b/math2svg/sample.md index 9c24d609..ef268610 100644 --- a/math2svg/sample.md +++ b/math2svg/sample.md @@ -1,9 +1,3 @@ ---- -header-includes: - - '\newcommand{\j}{{\text{j}}}' - - '\newcommand{\e}[1]{\,{\text{e}}^{#1}}' ---- - Only plane waves in the far field exhibit the [characteristic impedance of free space](https://en.wikipedia.org/wiki/Impedance_of_free_space), which is exactly: $$Z_0 = \frac{\left|\vec{E}\right|}{\left|\vec{H}\right|} = \sqrt{\frac{\mu_0}{\epsilon_0}} = \mu_0\cdot c_0 \approx 376.73\,\Omega$$ diff --git a/math2svg/sample.yaml b/math2svg/sample.yaml new file mode 100644 index 00000000..f52cdbc1 --- /dev/null +++ b/math2svg/sample.yaml @@ -0,0 +1,5 @@ +--- +header-includes: | + \newcommand{\j}{\text{j}} + \newcommand{\e}[1]{\,\text{e}^{#1}} +... From c8975eace26c5a30363661a5d2c16a118e9e3e00 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Wed, 14 Oct 2020 16:28:43 +0200 Subject: [PATCH 24/50] configuration over --metadata key values --- math2svg/Makefile | 10 +++++++-- math2svg/math2svg.lua | 52 ++++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/math2svg/Makefile b/math2svg/Makefile index 288aed91..afd7f2df 100644 --- a/math2svg/Makefile +++ b/math2svg/Makefile @@ -1,10 +1,16 @@ DIFF ?= diff --strip-trailing-cr -u test: sample.md math2svg.lua - @pandoc --mathml --lua-filter=math2svg.lua --to=html sample.yaml $< \ + @pandoc \ + --mathml --lua-filter=math2svg.lua \ + -M math2svg_font='Gyre-Pagella' \ + --to=html sample.yaml $< \ | $(DIFF) expected.html - expected: sample.md math2svg.lua - pandoc --mathml --lua-filter=math2svg.lua --output=expected.html sample.yaml $< + pandoc \ + --mathml --lua-filter=math2svg.lua \ + -M math2svg_font='Gyre-Pagella' \ + --output=expected.html sample.yaml $< .PHONY: test diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 875915aa..23cca889 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -41,44 +41,49 @@ -- $ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d --- Indicate with true or false whether DisplayMath and InlineMath should be converted to SVG. +-- By default, DisplayMath is converted to SVG, whereas InlineMath is not. local display2svg = true local inline2svg = false --- The fallback is MathML if pandoc is executed with the --mathml argument. --- MathML output gets generated much faster than SVG output. --- Moreover, MathML is well suited for InlineMath as line heights are kept small. +-- The fallback is MathML when pandoc is executed with the --mathml argument. - --- Enter here the full path to the tex2svg binary of mathjax-node-cli. --- The full path can be found with the following command on *nix, respectively Windows: --- $ which -a tex2svg --- > where tex2svg +-- The full path to the tex2svg binary of the mathjax-node-cli package. local tex2svg = '/usr/local/bin/tex2svg' - --- Speech text inclusion +-- Speech text inclusion local speech = false -speech = tostring(speech) --- Automatic line breaking +-- Automatic line breaking local linebreaks = true -linebreaks = tostring(linebreaks) --- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html +-- The default MathJax font local font = 'TeX' -font = 'Gyre-Pagella' +-- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html -- ex size in pixels local ex = 6 -ex = tostring(ex) --- container width in ex +-- Container width in ex local width = 100 -width = tostring(width) -- String of extensions to be loaded at run time --- Available extensions are at: /usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/ local extensions = '' +-- Available extensions are listed in: +-- /usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/ + + +function Meta(meta) + + display2svg = meta.math2svg_display2svg or display2svg + inline2svg = meta.math2svg_inline2svg or inline2svg + tex2svg = tostring(meta.math2svg_tex2svg or tex2svg) + speech = tostring(meta.math2svg_speech or speech) + linebreaks = tostring(meta.math2svg_linebreaks or linebreaks) + font = tostring(meta.math2svg_font or font) + ex = tostring(meta.math2svg_ex or ex) + width = tostring(meta.math2svg_width or width) + extensions = tostring(meta.math2svg_extensions or extensions) + +end function Math(elem) @@ -126,3 +131,10 @@ function Math(elem) end end + + +-- Redefining the execution order. +return { + {Meta = Meta}, + {Math = Math} +} From 0d9e3e3629c45561a156243d711dd46464a17944 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Thu, 15 Oct 2020 13:42:18 +0200 Subject: [PATCH 25/50] README.md math2svg.lua --- math2svg/README.md | 13 ++++++++++++- math2svg/math2svg.lua | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index 95975ada..b48318b2 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -44,12 +44,23 @@ $ sudo npm install --global mathjax-node-cli ## Usage To be used as a [Pandoc Lua filter](https://pandoc.org/lua-filters.html). -[MathML](https://en.wikipedia.org/wiki/MathML) should be set as a fallback. +[MathML](https://en.wikipedia.org/wiki/MathML) should be set as a fallback with the `--mathml` argument. ```bash pandoc --mathml --filter='math2svg.lua' ``` +MathML output gets generated much faster than SVG output. +Moreover, MathML is well suited for InlineMath as line heights are kept small. + +Enter here the full path to the `tex2svg` binary of `mathjax-node-cli`. +The full path can be found with the following command on \*nix, respectively Windows: + +```bash +$ which -a tex2svg +> where tex2svg +``` + ## Privacy diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 23cca889..0a3b3a2e 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -41,14 +41,14 @@ -- $ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d +-- The full path to the tex2svg binary of the mathjax-node-cli package. +local tex2svg = '/usr/local/bin/tex2svg' + -- By default, DisplayMath is converted to SVG, whereas InlineMath is not. local display2svg = true local inline2svg = false -- The fallback is MathML when pandoc is executed with the --mathml argument. --- The full path to the tex2svg binary of the mathjax-node-cli package. -local tex2svg = '/usr/local/bin/tex2svg' - -- Speech text inclusion local speech = false From e40396ec92c4d90f47b3aa95669124da858e073c Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Thu, 15 Oct 2020 23:10:50 +0200 Subject: [PATCH 26/50] Documentation completed (#1) * README.md --metadata table * Update README.md * Update README.md * README.md * documentation * documentation Co-authored-by: Serge Y. Stroobandt --- math2svg/README.md | 79 +++++++++++++++++++++++++++++++++++++++---- math2svg/math2svg.lua | 12 +++---- 2 files changed, 78 insertions(+), 13 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index b48318b2..51c4b42f 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -10,8 +10,8 @@ to [MathJax](https://www.mathjax.org/) generated [scalable vector graphics (SVG)](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) in any of the [available MathJax fonts](https://docs.mathjax.org/en/latest/output/fonts.html). -This is useful when a CSS paged media engine cannot process complex JavaScript -as required by MathJax. +This is useful when a CSS paged media engine (such as [Prince XML](https://www.princexml.com)) +cannot process complex JavaScript as required by MathJax. See: for information about CSS paged media, a [W3C standard](https://www.w3.org/TR/css-page-3/). @@ -32,7 +32,8 @@ $ brew install pandoc nodejs npm > choco install pandoc nodejs npm ``` -Then, install `mathjax-node-cli` using `npm`. +Then, by means of node's package manager `npm`, install the `mathjax-node-cli` package. +This package comes with the `tex2svg` executable. Leave out the `sudo` on Windows. ```bash @@ -50,17 +51,80 @@ To be used as a [Pandoc Lua filter](https://pandoc.org/lua-filters.html). pandoc --mathml --filter='math2svg.lua' ``` -MathML output gets generated much faster than SVG output. -Moreover, MathML is well suited for InlineMath as line heights are kept small. +The math2svg filter is entirely configurable over [`--metadata` key value pairs](https://pandoc.org/MANUAL.html#reader-options). +Nine configuration keys are available with sensible default values. +Hence, depending on your system and intentions, not all keys are necessarily required. -Enter here the full path to the `tex2svg` binary of `mathjax-node-cli`. -The full path can be found with the following command on \*nix, respectively Windows: +|key|default value| +|:--|:-----------:| +|`math2svg_path`|`'/usr/local/bin/tex2svg'`| +|`math2svg_display2svg`|`true`| +|`math2svg_inline2svg`|`false`| +|`math2svg_speech`|`false`| +|`math2svg_linebreaks`|`true`| +|`math2svg_font`|`'TeX'`| +|`math2svg_ex`|`6`| +|`math2svg_width`|`100`| +|`math2svg_extensions`|`''`| + + +### Key value `math2svg_path` +This string key value is required when, on your system, the full path to the `tex2svg` executable +of the `mathjax-node-cli` package differs from the default `'/usr/local/bin/tex2svg'` +This is certainly the case on Windows systems. + +The full path to `tex2svg` can be found with the following command on \*nix, respectively Windows: ```bash $ which -a tex2svg > where tex2svg ``` +### Key values `math2svg_display2svg` and `math2svg_inline2svg` +These boolean key values specify whether display math, respectively inline math, +should be converted to SVG by the filter. +The defaults convert display math to SVG, whereas inline math falls back to MathML +when `--mathml` was specified at `pandoc` evocation. +These defaults offer the following benefits: + +- MathML output gets generated much faster than SVG output. +- Moreover, MathML is well suited for InlineMath as line heights are kept small. + + +### Key value `math2svg_speech` +This boolean key value controls whether textual annotations for speech generation are added to SVG formula. +The default is `false`. + +### Key value `math2svg_linebreaks` +This boolean key value automatic switches automatic line breaking. +The default is `true`. + + +### Key value `math2svg_font` +This string key value allows to specify a [MathJax font](https://docs.mathjax.org/en/latest/output/fonts.html) different from the default `'TeX'` font. +The string should correspond to the local directory name of the font in the `mathjax-node-cli` installation directory. +For example, the key value string for the font in `/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/fonts/HTML-CSS/Gyre-Pagella/` would simply be +`Gyre-Pagella`. + + +### Key value `math2svg_ex` +This positive integer key value sets the `ex` unit in pixels. +The default value is `6` pixels. + + +### Key value `math2svg_width` +This positive integer key value sets the container width in `ex` units for line breaking and tags. +The default value is `100` ex. + + +### Key value `math2svg_extensions` +This string key value allows to load one or more comma separated [MathJax extensions for TeX and LaTeX](https://docs.mathjax.org/en/latest/input/tex/extensions.html) present on the system. +These MathJaX extensions reside in a subdirectory of the `mathjax-node-cli` installation directory. + +Take for example, the installation directory of the extensions is `/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/` +It contains a subdirectory `TeX` with the extension file `AMSmath.js`. +This MathJaX extension can be loaded by specifying the string `'TeX/AMSmath'` as the value of the `math2svg_extensions` key. + ## Privacy @@ -71,6 +135,7 @@ For code auditing, see also: - - +- ## License diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 0a3b3a2e..739d85b3 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -49,25 +49,25 @@ local display2svg = true local inline2svg = false -- The fallback is MathML when pandoc is executed with the --mathml argument. --- Speech text inclusion +-- Textual annotation for speech local speech = false -- Automatic line breaking local linebreaks = true --- The default MathJax font +-- MathJax font local font = 'TeX' -- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html --- ex size in pixels +-- ex unit size in pixels local ex = 6 --- Container width in ex +-- Container width in ex for line breaking and tags local width = 100 --- String of extensions to be loaded at run time +-- String of MathJax extensions for TeX and LaTeX to be loaded at run time local extensions = '' --- Available extensions are listed in: +-- Available MathJax extensions are listed in: -- /usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/ From 6c1410d08576c8abc7716b450540c2f3a0edc12c Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Thu, 15 Oct 2020 23:50:07 +0200 Subject: [PATCH 27/50] README.md --- math2svg/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index 51c4b42f..e025b05e 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -82,13 +82,13 @@ $ which -a tex2svg ### Key values `math2svg_display2svg` and `math2svg_inline2svg` These boolean key values specify whether display math, respectively inline math, -should be converted to SVG by the filter. -The defaults convert display math to SVG, whereas inline math falls back to MathML +should be converted to [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) by the filter. +The defaults convert display math to SVG, whereas inline math falls back to [MathML](https://en.wikipedia.org/wiki/MathML) when `--mathml` was specified at `pandoc` evocation. These defaults offer the following benefits: - MathML output gets generated much faster than SVG output. -- Moreover, MathML is well suited for InlineMath as line heights are kept small. +- Moreover, MathML is well suited for inline math as line heights are kept small. ### Key value `math2svg_speech` From b52cf39bce19e434a3cd91bee453fd8b13704418 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Fri, 16 Oct 2020 08:07:10 +0200 Subject: [PATCH 28/50] README.md --- math2svg/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/math2svg/README.md b/math2svg/README.md index e025b05e..610455ab 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -126,6 +126,26 @@ It contains a subdirectory `TeX` with the extension file `AMSmath.js`. This MathJaX extension can be loaded by specifying the string `'TeX/AMSmath'` as the value of the `math2svg_extensions` key. +### Adding `header-includes` +It might turn out useful to systematically include LaTeX macros, for example as shown below, a series of `\newcommand`. + +```latex +--- +header-includes: | + \newcommand{\j}{\text{j}} + \newcommand{\e}[1]{\,\text{e}^{#1}} +... +``` + +This may be achieved either by adding a [YAML](https://en.wikipedia.org/wiki/YAML) block at the top of the input document, +or by having a separate YAML document loaded before the input document. +In the latter case, simply evoke `pandoc` as follows: + +```bash +pandoc --mathml --filter='math2svg.lua' header-includes.yaml input.md +``` + + ## Privacy No Internet connection is established when creating MathJax SVG code using From 15ff17c0196b28734e7c823cdfdbef10a73afb16 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Fri, 16 Oct 2020 08:10:49 +0200 Subject: [PATCH 29/50] README.md --- math2svg/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math2svg/README.md b/math2svg/README.md index 610455ab..a9d304e5 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -137,7 +137,7 @@ header-includes: | ... ``` -This may be achieved either by adding a [YAML](https://en.wikipedia.org/wiki/YAML) block at the top of the input document, +This may be achieved either by adding a [YAML](https://en.wikipedia.org/wiki/YAML) block with the `header-includes` key value at the top of the input document, or by having a separate YAML document loaded before the input document. In the latter case, simply evoke `pandoc` as follows: From a0a1d58564bb31ac432701c364095a13d518af4a Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Fri, 16 Oct 2020 08:20:40 +0200 Subject: [PATCH 30/50] README.md --- math2svg/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math2svg/README.md b/math2svg/README.md index a9d304e5..553d9c1d 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -137,7 +137,7 @@ header-includes: | ... ``` -This may be achieved either by adding a [YAML](https://en.wikipedia.org/wiki/YAML) block with the `header-includes` key value at the top of the input document, +This may be achieved either by adding a [YAML](https://en.wikipedia.org/wiki/YAML) block with the [`header-includes`](https://pandoc.org/MANUAL.html#metadata-blocks) key value at the top of the input document, or by having a separate YAML document loaded before the input document. In the latter case, simply evoke `pandoc` as follows: From db42ee627b3e82dffe2d904f166d7ce8b4aff499 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Fri, 16 Oct 2020 14:45:03 +0200 Subject: [PATCH 31/50] 120 column lines & math2svg_tex2svg key value --- math2svg/README.md | 37 ++++++++++++++++++++++--------------- math2svg/math2svg.lua | 14 +++++++++++--- math2svg/sample.md | 3 ++- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index 553d9c1d..edb748a8 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -51,13 +51,14 @@ To be used as a [Pandoc Lua filter](https://pandoc.org/lua-filters.html). pandoc --mathml --filter='math2svg.lua' ``` -The math2svg filter is entirely configurable over [`--metadata` key value pairs](https://pandoc.org/MANUAL.html#reader-options). +The math2svg filter is entirely configurable over +[`--metadata` key value pairs](https://pandoc.org/MANUAL.html#reader-options). Nine configuration keys are available with sensible default values. Hence, depending on your system and intentions, not all keys are necessarily required. |key|default value| |:--|:-----------:| -|`math2svg_path`|`'/usr/local/bin/tex2svg'`| +|`math2svg_tex2svg`|`''`| |`math2svg_display2svg`|`true`| |`math2svg_inline2svg`|`false`| |`math2svg_speech`|`false`| @@ -68,10 +69,9 @@ Hence, depending on your system and intentions, not all keys are necessarily req |`math2svg_extensions`|`''`| -### Key value `math2svg_path` -This string key value is required when, on your system, the full path to the `tex2svg` executable -of the `mathjax-node-cli` package differs from the default `'/usr/local/bin/tex2svg'` -This is certainly the case on Windows systems. +### Key value `math2svg_tex2svg` +This string key value is only required when, on your system, the path to the `tex2svg` executable +of the `mathjax-node-cli` package is not present in the `$PATH` environment variable. The full path to `tex2svg` can be found with the following command on \*nix, respectively Windows: @@ -83,8 +83,8 @@ $ which -a tex2svg ### Key values `math2svg_display2svg` and `math2svg_inline2svg` These boolean key values specify whether display math, respectively inline math, should be converted to [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) by the filter. -The defaults convert display math to SVG, whereas inline math falls back to [MathML](https://en.wikipedia.org/wiki/MathML) -when `--mathml` was specified at `pandoc` evocation. +The defaults convert display math to SVG, whereas inline math falls back to +[MathML](https://en.wikipedia.org/wiki/MathML) when `--mathml` was specified at `pandoc` evocation. These defaults offer the following benefits: - MathML output gets generated much faster than SVG output. @@ -101,10 +101,12 @@ The default is `true`. ### Key value `math2svg_font` -This string key value allows to specify a [MathJax font](https://docs.mathjax.org/en/latest/output/fonts.html) different from the default `'TeX'` font. +This string key value allows to specify a [MathJax font](https://docs.mathjax.org/en/latest/output/fonts.html) +different from the default `'TeX'` font. The string should correspond to the local directory name of the font in the `mathjax-node-cli` installation directory. -For example, the key value string for the font in `/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/fonts/HTML-CSS/Gyre-Pagella/` would simply be -`Gyre-Pagella`. +For example, the key value string for the font in +`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/fonts/HTML-CSS/Gyre-Pagella/` +would simply be `Gyre-Pagella`. ### Key value `math2svg_ex` @@ -118,12 +120,16 @@ The default value is `100` ex. ### Key value `math2svg_extensions` -This string key value allows to load one or more comma separated [MathJax extensions for TeX and LaTeX](https://docs.mathjax.org/en/latest/input/tex/extensions.html) present on the system. +This string key value allows to load one or more comma separated +[MathJax extensions for TeX and LaTeX](https://docs.mathjax.org/en/latest/input/tex/extensions.html) +present on the system. These MathJaX extensions reside in a subdirectory of the `mathjax-node-cli` installation directory. -Take for example, the installation directory of the extensions is `/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/` +Take for example, the installation directory of the extensions is +`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/` It contains a subdirectory `TeX` with the extension file `AMSmath.js`. -This MathJaX extension can be loaded by specifying the string `'TeX/AMSmath'` as the value of the `math2svg_extensions` key. +This MathJaX extension can be loaded by specifying the string `'TeX/AMSmath'` +as the value of the `math2svg_extensions` key. ### Adding `header-includes` @@ -137,7 +143,8 @@ header-includes: | ... ``` -This may be achieved either by adding a [YAML](https://en.wikipedia.org/wiki/YAML) block with the [`header-includes`](https://pandoc.org/MANUAL.html#metadata-blocks) key value at the top of the input document, +This may be achieved either by adding a [YAML](https://en.wikipedia.org/wiki/YAML) block with +the [`header-includes`](https://pandoc.org/MANUAL.html#metadata-blocks) key value at the top of the input document, or by having a separate YAML document loaded before the input document. In the latter case, simply evoke `pandoc` as follows: diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 739d85b3..3e033e2b 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -42,7 +42,7 @@ -- The full path to the tex2svg binary of the mathjax-node-cli package. -local tex2svg = '/usr/local/bin/tex2svg' +local tex2svg = 'tex2svg' -- By default, DisplayMath is converted to SVG, whereas InlineMath is not. local display2svg = true @@ -73,9 +73,9 @@ local extensions = '' function Meta(meta) + tex2svg = tostring(meta.math2svg_tex2svg or tex2svg) display2svg = meta.math2svg_display2svg or display2svg inline2svg = meta.math2svg_inline2svg or inline2svg - tex2svg = tostring(meta.math2svg_tex2svg or tex2svg) speech = tostring(meta.math2svg_speech or speech) linebreaks = tostring(meta.math2svg_linebreaks or linebreaks) font = tostring(meta.math2svg_font or font) @@ -90,7 +90,15 @@ function Math(elem) local svg = nil local tags = nil - local argumentlist = {'--speech', speech, '--linebreaks', linebreaks, '--font', font, '--ex', ex, '--width', width, '--extensions', extensions, elem.text} + local argumentlist = { + '--speech', speech, + '--linebreaks', linebreaks, + '--font', font, + '--ex', ex, + '--width', width, + '--extensions', extensions, + elem.text + } -- The available options for tex2svg are: --help Show help [boolean] diff --git a/math2svg/sample.md b/math2svg/sample.md index ef268610..292273d7 100644 --- a/math2svg/sample.md +++ b/math2svg/sample.md @@ -1,4 +1,5 @@ -Only plane waves in the far field exhibit the [characteristic impedance of free space](https://en.wikipedia.org/wiki/Impedance_of_free_space), which is exactly: +Only plane waves in the far field exhibit the +[characteristic impedance of free space](https://en.wikipedia.org/wiki/Impedance_of_free_space), which is exactly: $$Z_0 = \frac{\left|\vec{E}\right|}{\left|\vec{H}\right|} = \sqrt{\frac{\mu_0}{\epsilon_0}} = \mu_0\cdot c_0 \approx 376.73\,\Omega$$ From 0d3876c8c56da4a1223fcdf4e9ca209e6136baee Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Fri, 16 Oct 2020 14:59:03 +0200 Subject: [PATCH 32/50] README.md privacy statement --- math2svg/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index edb748a8..e601841e 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -15,7 +15,8 @@ cannot process complex JavaScript as required by MathJax. See: for information about CSS paged media, a [W3C standard](https://www.w3.org/TR/css-page-3/). -No Internet connection is required for SVG conversions, resulting in absolute privacy. +No Internet connection is required when generating or viewing SVG formulas, resulting in both absolute privacy +and offline robustness. ## Requirements @@ -157,7 +158,10 @@ pandoc --mathml --filter='math2svg.lua' header-includes.yaml input.md No Internet connection is established when creating MathJax SVG code using the `tex2svg` command of [`mathjax-node-cli`](https://github.com/mathjax/mathjax-node-cli). -Hence, formulas in SVG can be created offline and will remain private. +Nor will any Internet connection be established when viewing an SVG formula. + +Hence, formulas in SVG can be created and viewed offline whilst remaining private. + For code auditing, see also: - From 237ce0c2b9ab6007d17820408a8fdb476212cf5f Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Fri, 16 Oct 2020 15:09:19 +0200 Subject: [PATCH 33/50] Makefile --- math2svg/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/math2svg/Makefile b/math2svg/Makefile index afd7f2df..0f3d076f 100644 --- a/math2svg/Makefile +++ b/math2svg/Makefile @@ -10,6 +10,7 @@ test: sample.md math2svg.lua expected: sample.md math2svg.lua pandoc \ --mathml --lua-filter=math2svg.lua \ + -M math2svg_tex2svg='/usr/local/bin/tex2svg' \ -M math2svg_font='Gyre-Pagella' \ --output=expected.html sample.yaml $< From 0691b006c39995b2fe49b0ba0cd3d7086f0a00bc Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Fri, 16 Oct 2020 17:42:53 +0200 Subject: [PATCH 34/50] --- math2svg/expected.html | 12 ++++++------ math2svg/math2svg.lua | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/math2svg/expected.html b/math2svg/expected.html index d889ad96..31e21f28 100644 --- a/math2svg/expected.html +++ b/math2svg/expected.html @@ -1,5 +1,5 @@

Only plane waves in the far field exhibit the characteristic impedance of free space, which is exactly:

-

+

@@ -86,7 +86,7 @@ -

+

where:
c0=299792458msc_0 = 299\,792\,458\,\frac{\text{m}}{\text{s}}: the speed of light in free space
μ0=4π107Hm\mu_0 = 4\pi\cdot10^{-7}\frac{\text{H}}{\text{m}}: the free space permeability
@@ -94,7 +94,7 @@ Z0Z_0: the characteristic impedance of free space

Euler’s formula:

-

+

@@ -140,10 +140,10 @@ -

+


The input impedance Zin,shortZ_\text{in,$\,$short} of a transmission line stub terminated in a short circuit is given by:

-

+

@@ -215,7 +215,7 @@ -

+

where:
γ=α+jβ\gamma = \alpha + \text{j}\beta is the propagation constant γ\gamma,
α\alpha is the attenuation constant, and
diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 3e033e2b..8384b934 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -113,7 +113,7 @@ function Math(elem) if elem.mathtype == 'DisplayMath' and display2svg then svg = pandoc.pipe(tex2svg, argumentlist, '') - tags = {'
', '
'} + tags = {'', ''} elseif elem.mathtype == 'InlineMath' and inline2svg then table.insert(argumentlist, 1, '--inline') @@ -134,6 +134,7 @@ function Math(elem) end else + return elem end From 02354d0f23f30b06f45b9ab94ad0a9c1747c5b26 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sat, 17 Oct 2020 11:18:29 +0200 Subject: [PATCH 35/50] description --- math2svg/README.md | 5 +++-- math2svg/math2svg.lua | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index e601841e..a132a06f 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -8,7 +8,8 @@ for [Pandoc](https://pandoc.org/) converts [LaTeX math](https://en.wikibooks.org/wiki/LaTeX/Mathematics) to [MathJax](https://www.mathjax.org/) generated [scalable vector graphics (SVG)](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) -in any of the [available MathJax fonts](https://docs.mathjax.org/en/latest/output/fonts.html). +for insertion into the output document in a standalone manner. +SVG output is in any of the [available MathJax fonts](https://docs.mathjax.org/en/latest/output/fonts.html). This is useful when a CSS paged media engine (such as [Prince XML](https://www.princexml.com)) cannot process complex JavaScript as required by MathJax. @@ -16,7 +17,7 @@ See: for information about CSS paged media, a [W3C standard](https://www.w3.org/TR/css-page-3/). No Internet connection is required when generating or viewing SVG formulas, resulting in both absolute privacy -and offline robustness. +and offline, standalone robustness. ## Requirements diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 8384b934..e047b0e2 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -1,9 +1,11 @@ -- DESCRIPTION -- -- This Lua filter for Pandoc converts LaTeX math to MathJax generated --- scalable vector graphics (SVG) in any of the available MathJax fonts. +-- scalable vector graphics (SVG) for insertion into the output document +-- in a standalone manner. SVG output is in any of the available MathJax fonts. -- This is useful when a CSS paged media engine cannot process complex JavaScript. --- No Internet connection is required for SVG conversions, resulting in absolute privacy. +-- No Internet connection is required when generating or viewing SVG formulas, +-- resulting in both absolute privacy and offline, standalone robustness. -- REQUIREMENTS, USAGE & PRIVACY From 473c360a46524e7467bf5f31bd7414254eba402a Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Sat, 17 Oct 2020 11:30:57 +0200 Subject: [PATCH 36/50] .travis.yml --- .travis.yml | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index b1f122b7..d08c590c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,8 @@ addons: - python-is-python3 - lilypond - lmodern + - nodejs + - npm - texlive-bibtex-extra - texlive-fonts-recommended - texlive-latex-recommended @@ -35,26 +37,30 @@ addons: - texlive-xetex before_install: -- unset CC -# Download and unpack the pandoc binary -- | - pushd $HOME - RELEASES_URL='https://github.com/jgm/pandoc/releases' - export PANDOCVERSION=$(curl --silent -I "$RELEASES_URL/latest" | sed -ne 's#[Ll]ocation:.*tag/\(.*\)$#\1#p' | tr -d "\n\r") - echo $PANDOCVERSION - travis_retry wget $RELEASES_URL/download/$PANDOCVERSION/pandoc-$PANDOCVERSION-linux-amd64.tar.gz - tar xvzf pandoc-$PANDOCVERSION-linux-amd64.tar.gz - popd -# Download plantuml.jar for plantuml filter -- | - pushd $HOME - travis_retry wget http://sourceforge.net/projects/plantuml/files/plantuml.jar - popd -- export PATH=$HOME/pandoc-$PANDOCVERSION/bin:$PATH -- export PLANTUML=$HOME/plantuml.jar + - unset CC + # Download and unpack the pandoc binary + - | + pushd $HOME + RELEASES_URL='https://github.com/jgm/pandoc/releases' + export PANDOCVERSION=$(curl --silent -I "$RELEASES_URL/latest" | sed -ne 's#[Ll]ocation:.*tag/\(.*\)$#\1#p' | tr -d "\n\r") + echo $PANDOCVERSION + travis_retry wget $RELEASES_URL/download/$PANDOCVERSION/pandoc-$PANDOCVERSION-linux-amd64.tar.gz + tar xvzf pandoc-$PANDOCVERSION-linux-amd64.tar.gz + popd + # Download plantuml.jar for plantuml filter + - | + pushd $HOME + travis_retry wget http://sourceforge.net/projects/plantuml/files/plantuml.jar + popd + - export PATH=$HOME/pandoc-$PANDOCVERSION/bin:$PATH + - export PLANTUML=$HOME/plantuml.jar -install: [] +install: []I + +before_script: + - sudo npm install --global mathjax-node-cli + - npm install --global mathjax-node-cli script: -- | - make test + - | + make test From 59fd787a5b00e7744409023c2482b3c49698797d Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 26 Oct 2020 19:30:18 +0100 Subject: [PATCH 37/50] README.md --- math2svg/README.md | 111 ++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 42 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index a132a06f..43368822 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -3,27 +3,25 @@ ## Description -This [Lua filter](https://pandoc.org/lua-filters.html) -for [Pandoc](https://pandoc.org/) -converts [LaTeX math](https://en.wikibooks.org/wiki/LaTeX/Mathematics) -to [MathJax](https://www.mathjax.org/) generated -[scalable vector graphics (SVG)](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) -for insertion into the output document in a standalone manner. -SVG output is in any of the [available MathJax fonts](https://docs.mathjax.org/en/latest/output/fonts.html). - -This is useful when a CSS paged media engine (such as [Prince XML](https://www.princexml.com)) +This [Lua filter][pandoc.lua-filters] for [Pandoc][pandoc] converts +[LaTeX math][latex.math] to [MathJax][mathjax] generated +[scalable vector graphics (SVG)][svg] for insertion into the output document +in a standalone manner. +SVG output is in any of the [available MathJax fonts][mathjax.fonts]. + +This is useful when a CSS paged media engine (such as [Prince XML][prince]) cannot process complex JavaScript as required by MathJax. See: for information about CSS paged media, -a [W3C standard](https://www.w3.org/TR/css-page-3/). +a [W3C standard][w3c] -No Internet connection is required when generating or viewing SVG formulas, resulting in both absolute privacy -and offline, standalone robustness. +No Internet connection is required when generating or viewing SVG formulas, +resulting in both absolute privacy and offline, standalone robustness. ## Requirements -First, use the package manager of your operating system to install -`pandoc`, `nodejs` and `npm`. `brew` and `choco` are recommended package mangers for +First, use the package manager of your operating system to install `pandoc`, +`nodejs` and `npm`. `brew` and `choco` are recommended package mangers for respectively macOS and Windows. See: ```bash @@ -34,8 +32,8 @@ $ brew install pandoc nodejs npm > choco install pandoc nodejs npm ``` -Then, by means of node's package manager `npm`, install the `mathjax-node-cli` package. -This package comes with the `tex2svg` executable. +Then, by means of node's package manager `npm`, install the `mathjax-node-cli` +package. This package comes with the `tex2svg` executable. Leave out the `sudo` on Windows. ```bash @@ -46,17 +44,19 @@ $ sudo npm install --global mathjax-node-cli ## Usage -To be used as a [Pandoc Lua filter](https://pandoc.org/lua-filters.html). -[MathML](https://en.wikipedia.org/wiki/MathML) should be set as a fallback with the `--mathml` argument. +To be used as a [Pandoc Lua filter][pandoc.lua-filters]. +[MathML][mathml] should be set as a fallback with +the `--mathml` argument. ```bash pandoc --mathml --filter='math2svg.lua' ``` The math2svg filter is entirely configurable over -[`--metadata` key value pairs](https://pandoc.org/MANUAL.html#reader-options). +[`--metadata` key value pairs](pandoc.metadata). Nine configuration keys are available with sensible default values. -Hence, depending on your system and intentions, not all keys are necessarily required. +Hence, depending on your system and intentions, not all keys are necessarily +required. |key|default value| |:--|:-----------:| @@ -72,10 +72,12 @@ Hence, depending on your system and intentions, not all keys are necessarily req ### Key value `math2svg_tex2svg` -This string key value is only required when, on your system, the path to the `tex2svg` executable -of the `mathjax-node-cli` package is not present in the `$PATH` environment variable. +This string key value is only required when, on your system, the path to the +`tex2svg` executable of the `mathjax-node-cli` package is not present in the +`$PATH` environment variable. -The full path to `tex2svg` can be found with the following command on \*nix, respectively Windows: +The full path to `tex2svg` can be found with the following command on \*nix, +respectively Windows: ```bash $ which -a tex2svg @@ -84,18 +86,19 @@ $ which -a tex2svg ### Key values `math2svg_display2svg` and `math2svg_inline2svg` These boolean key values specify whether display math, respectively inline math, -should be converted to [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) by the filter. +should be converted to [SVG][svg] by the filter. The defaults convert display math to SVG, whereas inline math falls back to -[MathML](https://en.wikipedia.org/wiki/MathML) when `--mathml` was specified at `pandoc` evocation. +[MathML][mathml] when `--mathml` was specified at `pandoc` evocation. These defaults offer the following benefits: - MathML output gets generated much faster than SVG output. -- Moreover, MathML is well suited for inline math as line heights are kept small. +- Moreover, MathML is well suited for inline math as line heights are kept + small. ### Key value `math2svg_speech` -This boolean key value controls whether textual annotations for speech generation are added to SVG formula. -The default is `false`. +This boolean key value controls whether textual annotations for speech +generation are added to SVG formula. The default is `false`. ### Key value `math2svg_linebreaks` This boolean key value automatic switches automatic line breaking. @@ -103,9 +106,10 @@ The default is `true`. ### Key value `math2svg_font` -This string key value allows to specify a [MathJax font](https://docs.mathjax.org/en/latest/output/fonts.html) +This string key value allows to specify a [MathJax font][mathjax.fonts] different from the default `'TeX'` font. -The string should correspond to the local directory name of the font in the `mathjax-node-cli` installation directory. +The string should correspond to the local directory name of the font in the +`mathjax-node-cli` installation directory. For example, the key value string for the font in `/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/fonts/HTML-CSS/Gyre-Pagella/` would simply be `Gyre-Pagella`. @@ -117,15 +121,15 @@ The default value is `6` pixels. ### Key value `math2svg_width` -This positive integer key value sets the container width in `ex` units for line breaking and tags. -The default value is `100` ex. +This positive integer key value sets the container width in `ex` units for line +breaking and tags. The default value is `100` ex. ### Key value `math2svg_extensions` This string key value allows to load one or more comma separated -[MathJax extensions for TeX and LaTeX](https://docs.mathjax.org/en/latest/input/tex/extensions.html) -present on the system. -These MathJaX extensions reside in a subdirectory of the `mathjax-node-cli` installation directory. +[MathJax extensions for TeX and LaTeX][mathjax.tex.ext] present on the system. +These MathJaX extensions reside in a subdirectory of the `mathjax-node-cli` +installation directory. Take for example, the installation directory of the extensions is `/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/` @@ -135,7 +139,8 @@ as the value of the `math2svg_extensions` key. ### Adding `header-includes` -It might turn out useful to systematically include LaTeX macros, for example as shown below, a series of `\newcommand`. +It might turn out useful to systematically include LaTeX macros, for example as +shown below, a series of `\newcommand`. ```latex --- @@ -145,10 +150,10 @@ header-includes: | ... ``` -This may be achieved either by adding a [YAML](https://en.wikipedia.org/wiki/YAML) block with -the [`header-includes`](https://pandoc.org/MANUAL.html#metadata-blocks) key value at the top of the input document, -or by having a separate YAML document loaded before the input document. -In the latter case, simply evoke `pandoc` as follows: +This may be achieved either by adding a [YAML][yaml] block with the +[`header-includes`][panoc.header-includes] key value at the top of the input +document, or by having a separate YAML document loaded before the input +document. In the latter case, simply evoke `pandoc` as follows: ```bash pandoc --mathml --filter='math2svg.lua' header-includes.yaml input.md @@ -158,10 +163,11 @@ pandoc --mathml --filter='math2svg.lua' header-includes.yaml input.md ## Privacy No Internet connection is established when creating MathJax SVG code using -the `tex2svg` command of [`mathjax-node-cli`](https://github.com/mathjax/mathjax-node-cli). +the `tex2svg` command of [`mathjax-node-cli`][mathjax.node.cli]. Nor will any Internet connection be established when viewing an SVG formula. -Hence, formulas in SVG can be created and viewed offline whilst remaining private. +Hence, formulas in SVG can be created and viewed offline whilst remaining +private. For code auditing, see also: @@ -200,3 +206,24 @@ SOFTWARE. ```bash $ echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d ``` + + +[latex.math]: https://en.wikibooks.org/wiki/LaTeX/Mathematics + +[mathjax]: https://www.mathjax.org/ +[mathjax.fonts]: https://docs.mathjax.org/en/latest/output/fonts.html +[mathjax.node.cli]: https://github.com/mathjax/mathjax-node-cli +[mathjax.tex.ext]: https://docs.mathjax.org/en/latest/input/tex/extensions.html +[mathml]: https://en.wikipedia.org/wiki/MathML + +[pandoc]: https://pandoc.org/ +[pandoc.header-includes]: https://pandoc.org/MANUAL.html#metadata-blocks +[pandoc.lua-filters]: https://pandoc.org/lua-filters.html +[pandoc.metadata]: https://pandoc.org/MANUAL.html#reader-options +[prince]: https://www.princexml.com + +[svg]: https://en.wikipedia.org/wiki/Scalable_Vector_Graphics + +[w3c]: https://www.w3.org/TR/css-page-3/ + +[yaml]: https://en.wikipedia.org/wiki/YAML From 6811a498552cc5e2961fe5cd38cef597428e3bba Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 26 Oct 2020 21:18:53 +0100 Subject: [PATCH 38/50] README.md 80 columns --- math2svg/README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index 43368822..1f295f57 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -12,7 +12,7 @@ SVG output is in any of the [available MathJax fonts][mathjax.fonts]. This is useful when a CSS paged media engine (such as [Prince XML][prince]) cannot process complex JavaScript as required by MathJax. See: for information about CSS paged media, -a [W3C standard][w3c] +a [W3C standard][w3c]. No Internet connection is required when generating or viewing SVG formulas, resulting in both absolute privacy and offline, standalone robustness. @@ -111,8 +111,8 @@ different from the default `'TeX'` font. The string should correspond to the local directory name of the font in the `mathjax-node-cli` installation directory. For example, the key value string for the font in -`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/fonts/HTML-CSS/Gyre-Pagella/` -would simply be `Gyre-Pagella`. +`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/fonts/` +`HTML-CSS/Gyre-Pagella/` would simply be `Gyre-Pagella`. ### Key value `math2svg_ex` @@ -132,7 +132,8 @@ These MathJaX extensions reside in a subdirectory of the `mathjax-node-cli` installation directory. Take for example, the installation directory of the extensions is -`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/` +`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/` +`extensions/` It contains a subdirectory `TeX` with the extension file `AMSmath.js`. This MathJaX extension can be loaded by specifying the string `'TeX/AMSmath'` as the value of the `math2svg_extensions` key. @@ -151,7 +152,7 @@ header-includes: | ``` This may be achieved either by adding a [YAML][yaml] block with the -[`header-includes`][panoc.header-includes] key value at the top of the input +[`header-includes`][pandoc.header-includes] key value at the top of the input document, or by having a separate YAML document loaded before the input document. In the latter case, simply evoke `pandoc` as follows: From 0ccfcc1b24e7f66b1e91b2a69e750e6fe787f11a Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 26 Oct 2020 21:20:26 +0100 Subject: [PATCH 39/50] README.md 80 columns --- math2svg/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index 1f295f57..8150d350 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -111,8 +111,8 @@ different from the default `'TeX'` font. The string should correspond to the local directory name of the font in the `mathjax-node-cli` installation directory. For example, the key value string for the font in -`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/fonts/` -`HTML-CSS/Gyre-Pagella/` would simply be `Gyre-Pagella`. +`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/fonts/HTML-CSS/Gyre-Pagella/` +would simply be `Gyre-Pagella`. ### Key value `math2svg_ex` @@ -132,8 +132,7 @@ These MathJaX extensions reside in a subdirectory of the `mathjax-node-cli` installation directory. Take for example, the installation directory of the extensions is -`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/` -`extensions/` +`/usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/` It contains a subdirectory `TeX` with the extension file `AMSmath.js`. This MathJaX extension can be loaded by specifying the string `'TeX/AMSmath'` as the value of the `math2svg_extensions` key. From 4dd39ad69b7d8e800fb1cf58d1976bf087627038 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 26 Oct 2020 22:19:57 +0100 Subject: [PATCH 40/50] math2svg.lua 80 columns --- math2svg/math2svg.lua | 60 +++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index e047b0e2..3cb96f06 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -2,10 +2,11 @@ -- -- This Lua filter for Pandoc converts LaTeX math to MathJax generated -- scalable vector graphics (SVG) for insertion into the output document --- in a standalone manner. SVG output is in any of the available MathJax fonts. --- This is useful when a CSS paged media engine cannot process complex JavaScript. --- No Internet connection is required when generating or viewing SVG formulas, --- resulting in both absolute privacy and offline, standalone robustness. +-- in a standalone manner. SVG output is in any of the available MathJax +-- fonts. This is useful when a CSS paged media engine cannot process complex +-- JavaScript. No Internet connection is required when generating or viewing +-- SVG formulas, resulting in both absolute privacy and offline, standalone +-- robustness. -- REQUIREMENTS, USAGE & PRIVACY @@ -19,23 +20,23 @@ -- -- MIT License -- --- Permission is hereby granted, free of charge, to any person obtaining a copy --- of this software and associated documentation files (the "Software"), to deal --- in the Software without restriction, including without limitation the rights --- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --- copies of the Software, and to permit persons to whom the Software is --- furnished to do so, subject to the following conditions: +-- Permission is hereby granted, free of charge, to any person obtaining a +-- copy of this software and associated documentation files (the "Software"), +-- to deal in the Software without restriction, including without limitation +-- the rights to use, copy, modify, merge, publish, distribute, sublicense, +-- and/or sell copies of the Software, and to permit persons to whom the +-- Software is furnished to do so, subject to the following conditions: -- --- The above copyright notice and this permission notice shall be included in all --- copies or substantial portions of the Software. +-- The above copyright notice and this permission notice shall be included in +-- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --- SOFTWARE. +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +-- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +-- DEALINGS IN THE SOFTWARE. -- CONTACT @@ -59,7 +60,8 @@ local linebreaks = true -- MathJax font local font = 'TeX' --- Supported MathJax fonts are: https://docs.mathjax.org/en/latest/output/fonts.html +-- Supported MathJax fonts are: +-- https://docs.mathjax.org/en/latest/output/fonts.html -- ex unit size in pixels local ex = 6 @@ -70,7 +72,8 @@ local width = 100 -- String of MathJax extensions for TeX and LaTeX to be loaded at run time local extensions = '' -- Available MathJax extensions are listed in: --- /usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/extensions/ +-- /usr/local/lib/node_modules/mathjax-node-cli/node_modules/mathjax/unpacked/\ +-- extensions/ function Meta(meta) @@ -103,15 +106,16 @@ function Math(elem) } -- The available options for tex2svg are: - --help Show help [boolean] - --version Show version number [boolean] - --inline process as in-line TeX [boolean] - --speech include speech text [boolean] [default: true] - --linebreaks perform automatic line-breaking [boolean] - --font web font to use [default: "TeX"] - --ex ex-size in pixels [default: 6] - --width width of container in ex [default: 100] - --extensions extra MathJax extensions e.g. 'Safe,TeX/noUndefined' [default: ""] + --help Show help [boolean] + --version Show version number [boolean] + --inline process as in-line TeX [boolean] + --speech include speech text [boolean] [default: true] + --linebreaks perform automatic line-breaking [boolean] + --font web font to use [default: "TeX"] + --ex ex-size in pixels [default: 6] + --width width of container in ex [default: 100] + --extensions extra MathJax extensions [default: ""] +-- e.g. 'Safe,TeX/noUndefined' if elem.mathtype == 'DisplayMath' and display2svg then svg = pandoc.pipe(tex2svg, argumentlist, '') From 4719dfb9bc03f75993b7f8119bda1d9aad73a665 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 26 Oct 2020 22:25:53 +0100 Subject: [PATCH 41/50] Typo in README.md Co-authored-by: Christophe Dervieux --- math2svg/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math2svg/README.md b/math2svg/README.md index 8150d350..155a5759 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -21,7 +21,7 @@ resulting in both absolute privacy and offline, standalone robustness. ## Requirements First, use the package manager of your operating system to install `pandoc`, -`nodejs` and `npm`. `brew` and `choco` are recommended package mangers for +`nodejs` and `npm`. `brew` and `choco` are recommended package managers for respectively macOS and Windows. See: ```bash From bb6c2733000d47404097eba77eef4dec671d7e21 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Mon, 26 Oct 2020 22:51:43 +0100 Subject: [PATCH 42/50] .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d08c590c..1b5fd50d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,7 +55,7 @@ before_install: - export PATH=$HOME/pandoc-$PANDOCVERSION/bin:$PATH - export PLANTUML=$HOME/plantuml.jar -install: []I +install: [] before_script: - sudo npm install --global mathjax-node-cli From c94c9c0efbfc129cb6f79cb752cd8a0412172368 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Tue, 27 Oct 2020 00:08:53 +0100 Subject: [PATCH 43/50] .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 1b5fd50d..f614fb38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,6 +58,7 @@ before_install: install: [] before_script: + - sudo chown -R 2000:2000 "/home/travis/.npm" - sudo npm install --global mathjax-node-cli - npm install --global mathjax-node-cli From 58935cbfd80f1a2a500e72b74c307858dcc39001 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" Date: Tue, 27 Oct 2020 07:06:18 +0100 Subject: [PATCH 44/50] .travis.yml --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f614fb38..fd8fca6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,8 +58,6 @@ before_install: install: [] before_script: - - sudo chown -R 2000:2000 "/home/travis/.npm" - - sudo npm install --global mathjax-node-cli - npm install --global mathjax-node-cli script: From 55cfd17bf917e22d5492b99e28c351a86496e053 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" <1105595+stroobandt@users.noreply.github.com> Date: Tue, 27 Oct 2020 09:20:12 +0100 Subject: [PATCH 45/50] .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fd8fca6c..7a6aaa84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,7 @@ before_install: install: [] before_script: - - npm install --global mathjax-node-cli + - sudo npm install --global mathjax-node-cli script: - | From 4601caa27d2ecd76c3330ec3ad4878a6b9c2b01b Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" <1105595+stroobandt@users.noreply.github.com> Date: Thu, 14 Jan 2021 14:17:06 +0100 Subject: [PATCH 46/50] Dockerfile --- .travis.yml | 65 ----------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7a6aaa84..00000000 --- a/.travis.yml +++ /dev/null @@ -1,65 +0,0 @@ -# Use new container infrastructure to enable caching -sudo: false - -# Older Ubuntu versions use Lua 5.1 for luarocks, while 20.04 -# (focal) uses Lua 5.3. -dist: focal - -# Do not choose a language; we provide our own build tools. -language: minimal - -addons: - apt: - packages: - - aspell - - aspell-fr - - aspell-en - - imagemagick - - default-jre - - graphviz - - inkscape - - python3 - - python3-pip - - python3-tk - - python3-numpy - - python3-matplotlib - - python-is-python3 - - lilypond - - lmodern - - nodejs - - npm - - texlive-bibtex-extra - - texlive-fonts-recommended - - texlive-latex-recommended - - texlive-latex-extra - - texlive-pictures - - texlive-plain-generic - - texlive-xetex - -before_install: - - unset CC - # Download and unpack the pandoc binary - - | - pushd $HOME - RELEASES_URL='https://github.com/jgm/pandoc/releases' - export PANDOCVERSION=$(curl --silent -I "$RELEASES_URL/latest" | sed -ne 's#[Ll]ocation:.*tag/\(.*\)$#\1#p' | tr -d "\n\r") - echo $PANDOCVERSION - travis_retry wget $RELEASES_URL/download/$PANDOCVERSION/pandoc-$PANDOCVERSION-linux-amd64.tar.gz - tar xvzf pandoc-$PANDOCVERSION-linux-amd64.tar.gz - popd - # Download plantuml.jar for plantuml filter - - | - pushd $HOME - travis_retry wget http://sourceforge.net/projects/plantuml/files/plantuml.jar - popd - - export PATH=$HOME/pandoc-$PANDOCVERSION/bin:$PATH - - export PLANTUML=$HOME/plantuml.jar - -install: [] - -before_script: - - sudo npm install --global mathjax-node-cli - -script: - - | - make test From 267b99a1eb5a0f233f71fa088e1e04352a7f755e Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" <1105595+stroobandt@users.noreply.github.com> Date: Thu, 14 Jan 2021 14:30:03 +0100 Subject: [PATCH 47/50] Dockerfile --- .tools/Dockerfile | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.tools/Dockerfile b/.tools/Dockerfile index 23186352..8945afe6 100644 --- a/.tools/Dockerfile +++ b/.tools/Dockerfile @@ -7,9 +7,11 @@ RUN apt-get -q --no-allow-insecure-repositories update \ && DEBIAN_FRONTEND=noninteractive \ apt-get install --assume-yes --no-install-recommends \ aspell \ - aspell-fr \ aspell-en \ + aspell-fr \ + asymptote \ default-jre \ + dvisvgm \ graphviz \ imagemagick \ inkscape \ @@ -17,16 +19,18 @@ RUN apt-get -q --no-allow-insecure-repositories update \ lmodern \ luarocks \ make \ + nodejs \ + npm \ + python-is-python3 \ python3 \ + python3-matplotlib \ + python3-numpy \ python3-pip \ python3-tk \ - python3-numpy \ - python3-matplotlib \ - python-is-python3 \ texlive-bibtex-extra \ texlive-fonts-recommended \ - texlive-latex-recommended \ texlive-latex-extra \ + texlive-latex-recommended \ texlive-pictures \ texlive-plain-generic \ texlive-xetex \ @@ -36,6 +40,9 @@ ARG plantuml_jar=plantuml.1.2018.9.jar RUN wget https://sourceforge.net/projects/plantuml/files/${plantuml_jar} \ --quiet --output-document=/root/${plantuml_jar} ENV PLANTUML=/root/$plantuml_jar + +RUN npm install --global mathjax-node-cli + ENV DIFF="diff -u" ENV LC_ALL="C.UTF-8" ENV LANG="C.UTF-8" From 803c7a272eca50d8a6022e23625bb808dc094d49 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" <1105595+stroobandt@users.noreply.github.com> Date: Thu, 14 Jan 2021 14:49:14 +0100 Subject: [PATCH 48/50] year 2021 --- math2svg/README.md | 2 +- math2svg/math2svg.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index 155a5759..d78b4fd0 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -178,7 +178,7 @@ For code auditing, see also: ## License -Copyright (c) 2020 Serge Y. Stroobandt +Copyright (c) 2020-2021 Serge Y. Stroobandt MIT License diff --git a/math2svg/math2svg.lua b/math2svg/math2svg.lua index 3cb96f06..95b1f578 100644 --- a/math2svg/math2svg.lua +++ b/math2svg/math2svg.lua @@ -16,7 +16,7 @@ -- LICENSE -- --- Copyright (c) 2020 Serge Y. Stroobandt +-- Copyright (c) 2020-2021 Serge Y. Stroobandt -- -- MIT License -- From f70e9c539b201d3d58b017d73d3f483f25717c87 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" <1105595+stroobandt@users.noreply.github.com> Date: Sat, 16 Jan 2021 14:46:23 +0100 Subject: [PATCH 49/50] README.md --- math2svg/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/math2svg/README.md b/math2svg/README.md index d78b4fd0..819a2680 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -160,6 +160,31 @@ pandoc --mathml --filter='math2svg.lua' header-includes.yaml input.md ``` +## Adding equation numbers with CSS + +Here is how to add automatic equation numbers to the right, +whilst keeping display math equations centered. + +```css +span.math.display { + display: flex; + justify-content: flex-end; + align-items: center; + } + +span.math.display svg { + margin: 0 auto; + max-width: 85%; + } + +span.math.display:after { + counter-increment: equation; + content: '(' counter(equation) ')'; + font-weight: bold; + } +``` + + ## Privacy No Internet connection is established when creating MathJax SVG code using From 9f2f99da7d6f1f770c9aaae609b41b0ac5e83137 Mon Sep 17 00:00:00 2001 From: "Serge Y. Stroobandt" <1105595+stroobandt@users.noreply.github.com> Date: Sat, 16 Jan 2021 14:53:23 +0100 Subject: [PATCH 50/50] README.md --- math2svg/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/math2svg/README.md b/math2svg/README.md index 819a2680..28d82068 100644 --- a/math2svg/README.md +++ b/math2svg/README.md @@ -162,8 +162,12 @@ pandoc --mathml --filter='math2svg.lua' header-includes.yaml input.md ## Adding equation numbers with CSS -Here is how to add automatic equation numbers to the right, -whilst keeping display math equations centered. +When automatic equation numbers are desired, these need to be added using +[cascading style sheets (CSS)](https://en.wikipedia.org/wiki/CSS), +as JavaScript is not available in CSS paged media. + +Below example CSS code centers display math whilst adding equation numbers +to the right. ```css span.math.display {