JelteF / PyLaTeX

A Python library for creating LaTeX files
https://jeltef.github.io/PyLaTeX/
MIT License
2.24k stars 287 forks source link

How to properly add math and refs to captions #358

Open skwde opened 1 year ago

skwde commented 1 year ago

I fail to find out how to properly add math and references to captions. Unfortunately there is nothing mentioned in the examples.

Following a minimal working example from one of my tries:

doc = Document('basic')

a = Math(data=[
    '5',
    r'\cdot',
    r'10^{4}'
], inline=True, escape=False).dumps_content()

with doc.create(Figure(position='h!')) as fig:

    x = [1,2,3,4]
    plt.plot(x,x)
    fig.add_plot()
    fig.add_caption(f"abc ")

tex = doc.dumps()
print(tex)
doc.generate_pdf(clean_tex=True)

So how do I add math to the caption such that it is rendered correctly?

Something similar goes for references.