Currently if you run the sage command latex('a string') using sage (or sagetex) the latex output looks like: \text{\texttt{a{ }string}}. I would like to eliminate either of these (preferably the \texttt command) so that it would yield something that looks like \text{a{ }string} or, even better, \text{a string}. Unfortunately, the latex command seems to be defined in such a way that I can't seem to edit how it parses strings.

Currently I am using a latex package that seems to (among other things) make the \text command prevent expansion of the inner contents, much like a verbatim environment (I don't know if this is normal in latex as I never actually use the \text{} command myself), so with the way sage is outputting strings I am getting a whole bunch of \texttt{a{ }string} output to my document, rather than the intended a string.

Any suggestions on either a sage, or a latex fix for this? I would try to do some sort of forced expansion, but since everything is called via the \sage command, it isn't expandable, which leaves me unsure of what other avenues I could try to use to get this to work.


PS: Although you can use the commands mentioned above in a sage cell to get the results, here is a MWE, using the cls and packages I am using here:

string = "a string"
  • 1
    I don't have sage installed so I can't test it, but maybe \sagestr would be useful? According to the documentation '\sagestr is identical to \sage, but it does not run Sage's latex function on the code you give it; it simply runs the Sage code and pulls the result into your \LTX file'. – Marijn Jun 11 '18 at 10:58
  • 1
    See also a usage example on tex.stackexchange.com/questions/212792/… (at the end of the answer). – Marijn Jun 11 '18 at 10:59
  • @Marijn anyone can test anything Sage and SageTeX with no install, using CoCalc. – Samuel Lelièvre Jul 15 '18 at 11:48

Your Answer

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

Browse other questions tagged or ask your own question.