SageTeX-Output: Possible simplification sought
I created a minimal example for SageTeX:
x = 420 # Denominator
MyRange = 222
M = []
for n in range (1,MyRange):
if x == denominator(n/x):
M.append('$' + latex(n/x).replace(' ','') + '$')
else:
M.append('$' + '\\frac{' + "{}".format(n) + '}{' + "{}".format(x) + '}=' + latex(n/x).replace(' ','') + '$')
MyOut = ', '.join(M)
print(MyOut)
This gives:
It works! Just for interest, I wonder: does the 2nd else-output
M.append('$' + '\\frac{' + "{}".format(n) + '}{' + "{}".format(x) + '}=' + latex(n/x).replace(' ','') + '$')
really have to be so complicated or is there an easier way?
€dit: My SageTeX-MWE is:
\documentclass{article}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{sagetex}
\begin{document}
\section{In}
\begin{sageblock}
x = 420 # Denominator
MyRange = 222
M = []
for n in range (1,MyRange):
if x == denominator(n/x):
M.append('$' + latex(n/x).replace(' ','') + '$')
else:
M.append('$' + '\\frac{' + "{}".format(n) + '}{' + "{}".format(x) + '}=' + latex(n/x).replace(' ','') + '$')
MyOut = ', '.join(M)
#print MyOut
\end{sageblock}
\section{Out}
\baselineskip16pt \sagestr{MyOut}
\end{document}