1

I'm trying to create some maths exercises with SageTeX. Here's my code:

\documentclass{article}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
x=var("x")
A(x)=(x-2)^2-36
B(x)=1-(2*x-3)^2
formules=[]
for k in [A,B]:
    formules.append(k(x)==factor(k(x)))

enonce="" for k in formules: enonce+=f"""

${latex(k)}$"""

\end{sagesilent} \sagestr{enonce} \end{document}

The first compilation with pdflatex is OK. The compilation with sage is OK. However, the second compilation with pdflatex gives

! Paragraph ended before \@newl@bel was complete.

Could somebody please explain what's wrong?

gz839918
  • 1,938

1 Answers1

0

The log file tells us what errors LaTeX has found. You said, "The first compilation with pdflatex is OK. The compilation with sage is OK.". This means you should look in the sout file to see what information was given back to LaTeX. It looks like this:

enter image description here

I think ! Paragraph ended before \@newl@bel was complete. refers to the blank lines in your .sout file (an empty line ended the paragraph). I use raw strings, which allow for problematic string input such as \. This allows me to end the line of calculation with a new line using \newline.

\documentclass{article}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
x=var("x")
A(x)=(x-2)^2-36
B(x)=1-(2*x-3)^2
formules=[]
for k in [A,B]:
    formules.append(k(x)==factor(k(x)))

enonce= r"" for k in formules: enonce+=r"\noindent $%s$ \newline"%(latex(k)) \end{sagesilent} \sagestr{enonce} \end{document}

The result running in Cocalc has no errors:

enter image description here

If you wanted an empty line between the two lines shown in the above picture, add another \newline as in enonce+=r"\noindent $%s$ \newline \newline"%(latex(k)). You can also use \\ instead of \newline or put in a particular amount of space with, for example, \\[20pt].

DJP
  • 12,451