0

When using the environment sagecommandline of sagetex with long number output, how can I get automatic line breaks? I already tried to change sagetex.sty (putting breaklines=true at several places), but nothing changed. Here is my minimal example:

\documentclass[
a6paper, 11pt, oneside,
english,ngerman]{scrartcl}

% !TEX TS-program = sage % !TEX encoding = UTF-8 Unicode

\usepackage[headsep=0cm,footskip=1.5em,includeheadfoot=true, top=0cm,bottom=0cm,left=.5cm,right=.5cm,]{geometry} \usepackage{sagetex}

\lstdefinestyle{SageOutput}{style=DefaultSageOutput,breaklines=true}

\begin{document} \begin{sagecommandline} sage: factorial(100)+1 sage: factorial(50)+1 sage: factorial(10) \end{sagecommandline} \end{document}

  • I don't think you can. You could, however, get around it by combining the Sagemath template Dr Stein provided here combined with generating the nice looking output, like in my answer here using sagesilent and \sagestr whenever the output overflows. I think you'd have to get rid of line numbers to do this, though. – DJP Aug 16 '20 at 17:33

1 Answers1

1

Yes I can ... I found a solution myself:

\documentclass[ DIV=16, a6paper, 11pt]{scrartcl} 
% arara: lualatex
% arara: sagetex
% arara: lualatex
% !TEX TS-program = sage
% !TEX encoding = UTF-8 Unicode
\usepackage{seqsplit}
\usepackage{sagetex}
\lstset{
literate=
{1}{1\allowbreak}1
{2}{2\allowbreak}1
{3}{3\allowbreak}1
{4}{4\allowbreak}1
{5}{5\allowbreak}1
{6}{6\allowbreak}1
{7}{7\allowbreak}1
{8}{8\allowbreak}1
{9}{9\allowbreak}1
{0}{0\allowbreak}1,
breaklines=true}
\begin{document}
\begin{sagecommandline}
sage: factorial(50)
\end{sagecommandline}
\seqsplit{%
30414093201713378043612608166064768844377641568960512000000000000}
\end{document}
  • Great: +1, but people come to this site looking for answers that can help with their problems, too. Was the seqsplit package all that was needed? What does \lstset{ literate= do? How about \allowbreak? – DJP Aug 21 '20 at 12:21
  • a) 'seqsplit' does not work inside the env. sagecommandline, but inside math; I added it just for the sake of completeness; perhaps I should have left it out in order to not confuse people ... b) lstset{literate=...} is an option of the listings package; when having breaklines=true, this is not enough, you also have to tell listings that it is allowed to insert linebreaks after the figures 0, 1, ..., 9, which is not the case usually; – dantetante Aug 30 '20 at 14:34