XimeraProject / ximeraLatex

Author tools for creating Ximera activities
LaTeX Project Public License v1.3c
40 stars 35 forks source link

sage won't display strings correctly. #79

Open Zengez opened 6 years ago

Zengez commented 6 years ago

The short version: Sage code in Ximera won't display strings correctly, regardless of method used. The long version: Sage with Sagetex has two different mechanisms for displaying a string written in sage.

First method: \sage call of a variable that is a string; MWE:

\documentclass{ximera}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
string = "a string"
\end{sagesilent}
$\sage{string}$
\end{document}

If you compile the above, the PDF looks normal, albeit a little goofy (for reasons I will describe in the moment) outputting a block-text of a string. However, if you publish it to a website with Ximera, you end up getting the string \texttt{a{ }string} displayed. If you dig through the .sout file you will see that, weirdly, sage processes strings that are called via \sage by wrapping them in \text{\texttt{STRINGHERE}} with { } used to inject spaces. Presumably this is because \sage is only callable within mathemode, so they want the \text to denote it as text, and to make it line up nicely with other choices in display/math mode they wrap the internal mechanics with \texttt, which is a block-text style that uses uniform width text. However; weirdly, Ximera seems to be interpreting that \text command almost like a verbatim, so it is inputting the entire contents of the \text, including the \texttt command and all the associated braces.

Method 2: \sagestr command MWE:

\documentclass{ximera}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
string = "a string"
\end{sagesilent}
$\sagestr{string}$
\sagestr{string}
$\text{\sagestr{string}}$
\end{document}

Luckily, the guys that make sage realized we'd like to call strings outside of mathemode, and gave us the \sagestr command, which is callable in or out of mathemode. This simply displays the string of the variable as is, so if you compile the content of the top you will see "astring", a string and a string, where the first one looks goofy because it's text in mathemode, so latex interprets it as variables and removes whitespace. Again, however, Ximera seems to not like the idea of sending sage text that isn't in mathemode out to be processed, so the line not in mathemode just gets left as some weird @sageinline type reference, the one in the top comes out looking like a sequence of variables (ie not intelligible) and the last one comes out as \sagestr{string} because, again, text seems to turn it into verbatim for some reason.

For reference, I am running the Xronos version of this, which is the release right before the .dtx release, but this has been an ongoing problem since sage was released (for us at UF anyway) as supported in Ximera. I'm using the content of "Optional Packages" folder, specifically the "PackageLoader.sty", the "Useful-Sage-Macros.tex" and the "Useful-Validators.tex" file to produce this issue.