Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math in docstrings #225

Closed
domagojhack opened this issue Feb 18, 2021 · 8 comments
Closed

Math in docstrings #225

domagojhack opened this issue Feb 18, 2021 · 8 comments

Comments

@domagojhack
Copy link

Maybe I am missing something. Is there a way to make pdoc render tex math formulas? My docstrings contain a lot of them.

Formulas like this:

$\frac{x}{1}

Cheers

@mhils
Copy link
Member

mhils commented Feb 18, 2021

There is! I have just pushed an example to examples/math, does that do what you were looking for? 😃

@domagojhack
Copy link
Author

domagojhack commented Feb 18, 2021

Yes, thanks for the example. Formulas are now stylized like LaTeX math, however I am getting another issue (maybe not pdoc related). My fractions are not rendered properly.

for
$$\frac{w}{10} + i*day$$

I am getting

2021-02-18_16-16

instead of:

2021-02-18_16-20

UPDATE:

Double backslashes fixed the problem:

$$\\frac{w}{10} + i*day$$

mhils added a commit that referenced this issue Feb 18, 2021
@mhils
Copy link
Member

mhils commented Feb 18, 2021

Good catch, that can be confusing here. I've added an explanation to https://pdoc.dev/docs/math/math_demo.html 😃

@abubelinha
Copy link

@mhils I saw the explanation but I still cannot see formulas being rendered (same problem described above).

The math.html.jinja2 file linked there says "MathJax by default does not define $ as a math delimiter because it's commonly used in non-mathematical settings. We add it here."
Not sure if I understood correctly: that template is or is not already being used by default?
It is located in my pdoc/templates folder, but not in pdoc/templates/default. Should I move it there to activate it?

Currently, when using $$dist = \\sqrt { a^2+b^2 }$$ I just see $$dist = \sqrt { a^2+b^2 }$$ (the square root symbol is not being displayed, and $$ symbols are visible in resulting html documentation)

@mhils
Copy link
Member

mhils commented Jan 5, 2022

@abubelinha: This issue predates the current builtin implementation. You need to run pdoc --math ... to include MathJax and render formulas. Are you doing that?

Not sure if I understood correctly: that template is or is not already being used by default?

math.html.jinja2 is used by default if --math is passed.

@abubelinha
Copy link

Ah ... I see.
I am using pdoc as a library (#325), not from command line.
How do I pass --math in that case?

@mhils
Copy link
Member

mhils commented Jan 5, 2022

@abubelinha
Copy link

So the answer (for my own record) is:

import pdoc
pdoc.render.configure(math=True)
pdoc.pdoc( ... whatever ...)

Thanks a lot !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants