# Latex docstring for functions

**URL:** <https://discourse.julialang.org/t/latex-docstring-for-functions/87191>\
**Category:** General Usage\
**Tags:** documentation, latexstrings\
**Created:** [September 13, 2022, 7:48am UTC](https://discourse.julialang.org/t/latex-docstring-for-functions/87191 "2022-09-13T07:48:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rex\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rex_wang/32/35108_2.png) [@Rex\_Wang](https://discourse.julialang.org/u/Rex_Wang)\
**Post date:** [September 13, 2022, 7:48am UTC](https://discourse.julialang.org/t/latex-docstring-for-functions/87191/1 "2022-09-13T07:48:55Z")

</div>

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

It works fine following the instruction here: [LaTeX Syntax](https://juliadocs.github.io/Documenter.jl/stable/man/latex/#latex_syntax)

```plaintext
@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

 ![深度截图_选择区域_20220913153525](https://global.discourse-cdn.com/julialang/original/3X/0/c/0c8c3d23442548562d69b0d8d701a7aad38bb533.png)

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!

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [September 15, 2022, 6:01pm UTC](https://discourse.julialang.org/t/latex-docstring-for-functions/87191/2 "2022-09-15T18:01:26Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![mortenpi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mortenpi/32/158_2.png) [@mortenpi](https://discourse.julialang.org/u/mortenpi)\
**Post date:** [September 15, 2022, 8:31pm UTC](https://discourse.julialang.org/t/latex-docstring-for-functions/87191/3 "2022-09-15T20:31:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rex\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rex_wang/32/35108_2.png) [@Rex\_Wang](https://discourse.julialang.org/u/Rex_Wang)\
**Post date:** [September 17, 2022, 6:06am UTC](https://discourse.julialang.org/t/latex-docstring-for-functions/87191/4 "2022-09-17T06:06:53Z")

</div>

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

> [@digital\_carver](#):
>
> I’m not sure it’s the `tab` that’s causing the problem

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

Example1: case without subscripts

 ![深度截图_选择区域_20220917133528](https://global.discourse-cdn.com/julialang/original/3X/e/e/eebd8f78823172d5d76011841611bb65727d0f7b.png)

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

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/7/27c2a92d6e15b462dc5884ae461511d80ef80d79.png)

> [@mortenpi](#):
>
> This looks like is being rendered in a Jupyter notebook?

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

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

---

<div class="post-metadata">

**Author:** ![Rex\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rex_wang/32/35108_2.png) [@Rex\_Wang](https://discourse.julialang.org/u/Rex_Wang)\
**Post date:** [September 17, 2022, 6:22am UTC](https://discourse.julialang.org/t/latex-docstring-for-functions/87191/5 "2022-09-17T06:22:07Z")

</div>

ADD:

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

```plaintext
# 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

 ![深度截图_选择区域_20220917141533](https://global.discourse-cdn.com/julialang/original/3X/b/a/ba600d02eb8e75a9f5fca416829df04f62feaef3.png)

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

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/9/09730a6bcc5fb981ee2efc5e99e86a4af24ed202.png)

In vscode(ParseError):

 ![深度截图_选择区域_20220917141951](https://global.discourse-cdn.com/julialang/original/3X/3/0/30bac3d81f3d741c9d246b133f7bdffa2dcb2a45.png)

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