Latex docstring for functions

I’m trying to use latex strings for function documentation.

It works fine following the instruction here: LaTeX Syntax

@doc raw"""

balabala...

``some equations``
"""
myfun(x) = x

However, the tex string become invalid when I add the function description on the first line.

For example - - invalid texstring

It seems that the tab that appears at the beginning of the sentence will affect the rending of texstring, why is this happening.
Can someone give a good solution. Thank you very much!

I’m not sure it’s the tab that’s causing the problem - it might be the r₁ and r₂ in the signature. When you use latex in the docstring, the whole docstring is sent to a latex engine to be processed, and a lot of latex engines choke on unicode characters like the subscript and . (It looks like Documenter tries to use lualatex which should be able to handle these, but for some reason isn’t - maybe a missing \usepackage{fontspec} in the preamble.)

You can do either of:

  • replace the arguments names with r1 and r2
  • write them also using LaTeX syntax, (``r_1``::Poly, ``r_2``::Poly)
1 Like

This looks like is being rendered in a Jupyter notebook? The best way I can think if debugging this is to press F12 in the browser to open the browser developer tools and see if you get any MathJax/KaTeX errors in the JS console that might give you an idea why it’s not being rendered.

1 Like

Thanks for your replies!!! @digital_carver and @mortenpi

Yes. I should have provided more examples to say so.

Example1: case without subscripts

Example2: case without tab + nonspace at the first nonempty line

Thank you for pointing that out. Actually, I’m using the JupyterLab.

It turns out that the docstring works well for jupyter-notebook.

1 Like

ADD:

I’m using Ubuntu20.04, and the above are results in JupyterLab.

# versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, icelake-client)

In JupyterLab

In Jupyter-notebook before rending(works well too after rending)

In vscode(ParseError):

As a result, this might have to do with the verbatim environment in LaTeX string.