3

I am currently working on enhancing my LaTeX documents to involve complex mathematical equations. Managing these equations manually often leads to errors, especially when changing dependent equations elsewhere in the document. I have explored using GNU TeXmacs with Maxima for its integration with domain-specific languages, but I am looking for solutions that are more directly compatible with LaTeX.

The GitHub repository, Awesome-FLOSS-CAS, lists several FLOSS CAS tools, including Maxima and Sympy. While Python and Sympy offer extensive capabilities, the syntax and integration process is somewhat cumbersome. Therefore, I am considering using Maxima for its simpler syntax and direct LaTeX integration.

One potential method I've identified is to use the tex(...) command within Maxima to export equations into a text file and then include these in a LaTeX document with the \input{...} command. However, this method raises questions about managing variables and equations effectively in LaTeX.

I would appreciate hearing about the experiences and methods others have used to integrate CAS tools into LaTeX workflows. What are the best practices you recommend? Are there effective strategies for handling variable replacements or maintaining synchronicity between the CAS outputs and LaTeX inputs?

10
  • 2
    Search this site for sagetex; it's a package that gives you access to Sage, a CAS, along with Python programming language. Cocalc is the easiest way to get started as it gives you access to Sage (which is not part of your LaTeX distribution) without having to install on your computer.
    – DJP
    Commented May 3 at 21:39
  • 1
    @DJP OK! SageTeX seems interesting. thank you.
    – Foad
    Commented May 3 at 21:50
  • 1
    Perhaps knitr is of interest. Commented May 4 at 1:30
  • 1
    If you are downloading Sage onto your computer then Sage includes sagetex so you shouldn't use other versions that might not be compatible.This page shows where it is. If you use Cocalc, then you won't download Sage or sagetex; it is handled through Cocalc to be the most current versions
    – DJP
    Commented May 4 at 1:31
  • 1
    This page on FAQ and this page discuss using various open source software in LaTeX (through Cocalc).
    – DJP
    Commented May 4 at 1:48

2 Answers 2

3

Exploring the spectrum of solutions for integrating Computer Algebra Systems (CAS) into LaTeX, we see options ranging from manual to fully automated systems. Here's a comprehensive summary based on community feedback, existing solutions, and my own research.

Manual Integration

  • Maxima and LaTeX: Robert Dodier suggested a workflow where equations are generated using Maxima’s tex(...) function and manually integrated into LaTeX documents. This method, while straightforward, requires careful handling to ensure synchronization between the CAS output and LaTeX input.

Integrated Programming Languages

Several solutions allow direct embedding of programming languages into LaTeX, enabling dynamic document generation:

  • SageTeX: Integrates Sage into LaTeX, allowing for the execution of Sage code within LaTeX documents. SageTeX Documentation, Example of integrating SageTeX on YouTube
  • R with Sweave and knitr: These packages integrate R with LaTeX. Sweave and knitr allow for the inclusion of R code within LaTeX for dynamic content generation. knitr in a knutshell tutorial
  • PythonTeX and Sympytex: These tools integrate Python into LaTeX, with PythonTeX providing robust execution of Python code and Sympytex focusing on integrating SymPy for mathematical calculations. PythonTeX GitHub Repository
  • Martin R. Ehmsen's python.sty: Another method for embedding Python code within LaTeX documents. python.sty on CTAN, and example.
  • PerlTeX: Allows the embedding of Perl code within LaTeX documents. PerlTeX

Literal Programming vs. Integrated Solutions

While some refer to these integrated programming solutions as "literal programming," it's important to note the distinction. Literal programming typically involves co-locating code and documentation, which is slightly different from the execution of embedded code within LaTeX documents.

Extended LaTeX Programming

  • LuaTeX: Extends LaTeX to include Lua, allowing for scripting within documents, which can greatly enhance the capability to automate and handle complex operations. LuaTeX Official Site
  • L3 programming layer (expl3): Designed for LaTeX3, this provides a comprehensive programming interface, modernizing LaTeX programming practices. LaTeX3 expl3 Introduction
  • functional package: Offers a functional programming approach within LaTeX, serving as an alternative to expl3 or LuaTeX. functional package on CTAN

External Interaction

  • bashful package: Facilitates the interaction with external scripts through stdin and stdout, allowing LaTeX documents to interact with external programs. bashful package on CTAN
1

Couple more ideas to add to the others. I use Maxima a lot to handle equations in various ways and then generate TeX output which goes into a document. I hope these ideas give some inspiration to others.

(1) Often I work with a Maxima session in one terminal window and a text editor (editing a TeX document) in another and just tinker with expressions in Maxima until I get to a place where it's presentable, then call tex and just paste the output into a TeX document. I know that's primitive, but getting stuff to a point where it's presentable almost invariably involves a lot of trial and error, which shouldn't be preserved in the final document; I haven't found a better environment for that process, although maybe a tighter integration between the computational stuff and editing stuff could help -- is it possible R Studio could help with that? I haven't investigated.

(2) Someone mentioned knitr for R. There is a knitr plugin named rim for incorporating Maxima output in documents. See https://rcst.github.io/rim/ for examples of knitr output and https://github.com/rcst/rim for examples in R itself (the latter URL is also the Github project page). rim calls Maxima's tex1 function to generate TeX output, and also generates ASCII art (2-d layout), presentation MathML, and 1-d linear ASCII suitable for input.

(3) Jupyter (https://jupyter.org) comprises a general framework to support a notebook interface, and a very large collection of language-specific plugins, called kernels; there is a Jupyter kernel for Maxima called maxima-jupyter. See: https://github.com/robert-dodier/maxima-jupyter I use maxima-jupyter from time to time, but often with another Maxima session running in a separate terminal ... need to get stuff straight before pasting it into the notebook. maxima-jupyter calls Maxima's tex function to generate TeX, which is displayed by MathJax in the browser interface.

Incidentally, you might find Sympy or another system has a Jupyter kernel and then use that in a notebook.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .