orzih / mkdocs-with-pdf

Generate a single PDF file from MkDocs repository.
MIT License
336 stars 77 forks source link

Is it possible to render math equations? #147

Open adamryczkowski opened 1 year ago

adamryczkowski commented 1 year ago

How does one render math in mkdocs pdf? Is it actually supported? Here's my minimalistic attempt (after https://github.com/orzih/mkdocs-with-pdf/issues/75 ).

python -m venv venv
. venv/bin/activate
pip install mkdocs-with-pdf
mkdocs new test_math
cd test_math
echo "plugins:
  - with-pdf:
      render_js: true" >> mkdocs.yml 
echo "$$
a^2 + b^2 = c^2
$$
"" >> docs/index.html
mkdocs build

The output:

INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /home/Adama-docs/Adam/linux/tmp/mkdocs-with-pdf/samples/test_math/site
INFO     -  Number headings up to level 3.
INFO     -  Generate a table of contents up to heading level 2.
INFO     -  Generate a cover page with "default_cover.html.j2".
INFO     -  Converting <img> alignment(workaround).
INFO     -  Rendering on `Headless Chrome`(execute JS).
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
[0628/165909.566287:WARNING:sandbox_linux.cc(393)] InitializeSandbox() called with multiple threads in process gpu-process.
[0628/165909.573183:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.
INFO     -  Rendering for PDF.
INFO     -  Output a PDF to "/home/Adama-docs/Adam/linux/tmp/mkdocs-with-pdf/samples/test_math/site/pdf/document.pdf".
INFO     -  Converting 1 articles to PDF took 0.3s
INFO     -  Documentation built in 0.29 seconds

The document.pdf is empty. Not a single character is displayed.

I use Ubuntu 22.04 64bit. Python 3.10.6.

adamryczkowski commented 1 year ago

I've also tried adding

pip install mkdocs-material beautifulsoup4==4.9.3
echo "theme:
    name: 'material'
"" >> mkdocs.yml
mkdocs build

with the output:

INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /home/Adama-docs/Adam/linux/tmp/mkdocs-with-pdf/samples/test_math/site
INFO     -  Number headings up to level 3.
INFO     -  Generate a table of contents up to heading level 2.
INFO     -  Generate a cover page with "default_cover.html.j2".
INFO     -  Converting <img> alignment(workaround).
INFO     -  Rendering on `Headless Chrome`(execute JS).
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
[0628/170925.585340:WARNING:sandbox_linux.cc(393)] InitializeSandbox() called with multiple threads in process gpu-process.
[0628/170925.591491:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.
INFO     -  Rendering for PDF.
INFO     -  Output a PDF to "/home/Adama-docs/Adam/linux/tmp/mkdocs-with-pdf/samples/test_math/site/pdf/document.pdf".
INFO     -  Converting 1 articles to PDF took 0.3s
INFO     -  Documentation built in 0.42 seconds

Still, the same empty document.

akinmr commented 10 months ago

I'm using markdown-katex for equations and it renders well in both HTML and PDF output.

mkdocs new test_math
cd test_math
echo 'markdown_extensions:
  - markdown_katex:
plugins:
  - with-pdf:' >> mkdocs.yml 
echo '```math
a^2 + b^2 = c^2
```" >> docs/index.html
mkdocs build

generates what you want.