I would like to use pylatex to create only fragments of LaTeX (i.e., give a nice math-style format to a numpy array) for inclusion into another doc (i.e., Jupyter notebook).

It is easy to embed LaTeX into Jupyter output cells using the IPython.core.display.Latex display processor [as in IPython.display.Latex('Some LaTeX')]. I then can convert the notebook to LaTeX using my converter at https://github.com/NelisW/ipynb2tex, which can extract the LaTeX code from the mime type 'text/latex' object embedded in the output cell.

All the examples in the pylatex docs create full LaTeX documents including the class definition, \begin{document}, etc. If we can extract only smaller sections of latex code generated by pylatex, we can use such fragments inside the Jupyter notebook for later LaTeX typesetting.

Hence my question: is it possible to 'calculate' only small sections of LaTeX code with pylatex, instead of the full document?


Yes, this is possible. See the Library Usage page in the documentation: https://jeltef.github.io/PyLaTeX/current/usage.html#the-classes

Classes can be part of a single document, or can act as pieces on their own. With the dumps method, most classes can return their LaTeX-formatted code, and with the generate_tex method, this code can be written to a file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.