2

I'm planning a very flexible python program computing the steady states of a system of differential equations.

I want to print the output of this program into a .tex file as you can see in the following example.

Each variable and each constant gets its own tex command. I use \def instead of \newcommand \renewcommand, because \def doesn't returns an error if the command is already defined.

\documentclass[11pt,onehalfspacing,numbers=noenddot,openany]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[utf8]{inputenc}
\usepackage{oldgerm}
\usepackage{amsmath,amsthm,amssymb,eurosym,amsfonts}
\numberwithin{equation}{section}
\usepackage[ngerman]{babel}
\usepackage{xspace}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{pdfpages}
\begin{document}
\def\P{\mathrm{\P}}
\def\I{\mathrm{\I}}
\def\D{\mathrm{\D}}
\def\t{\mathrm{\t}}
\def\cp{\mathrm{c}_\mathrm{p}}

\chapter{Model 1}
\begin{equation}
\begin{aligned}
\P = \cp \I 
\end{aligned}
\end{equation}
\end{document}

The example results in the following error message

! TeX capacity exceeded, sorry [grouping levels=255].<recently read>    \math@bgroup \P

Well the program apologizes at least :-)

If I use \newcommand/\renewcommand I don't face these problems but I lose the flexibility to change the names of my constants/variables.

Do you know a nice work around solution for this problem?

Thank you in advance!
Alex

  • 1
    welcome to tex.sx. using \def has nothing to do with the problem. loops can be created just as easily by careless inclusion of the command name that's being defined being used in the expansion of the definition. – barbara beeton Nov 11 '16 at 14:23
  • It is almost impossible to exceed TeX capacity. If you do, you normally have a recursion without break. Which in fact you do. Please clarify what your defs should do. – MaestroGlanz Nov 11 '16 at 15:11
  • 2
    You probably want \DeclareMathOperator{\P}{P} and the same for the other letters. And don't use \def. – egreg Nov 11 '16 at 15:40
3

Your \P, defined \def\P{\mathrm{\P}}, calls an infinite loop.

You probably want \def\P{\mathrm{P}}. Similarly, \I, \D, \t.

  • 1
    not only \I, but all the one-letter commands are loopy. only the definition of \cp is correct. (looks like a case of uncleaned cut-and-paste.) – barbara beeton Nov 11 '16 at 14:21
  • @barbarabeeton Certainly. I have just pointed the source of error in the called definition. – Przemysław Scherwentke Nov 11 '16 at 14:26
  • @barbarabeeton You are right. Corrected. – Przemysław Scherwentke Nov 11 '16 at 15:09
  • Thank your for the answer. I wasn't aware of this loop. Well I just updated my code and it works – Alexander Tille Nov 11 '16 at 15:33

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.