Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

SageTeX-Output: Possible simplification sought

I created a minimal example for SageTeX:

x = 16       # Denominator
MyRange = 100

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:

image description

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?

SageTeX-Output: Possible simplification sought

I created a minimal example for SageTeX:

x = 16       # Denominator
MyRange = 100

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:

image description

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}

SageTeX-Output: Possible simplification sought

I created a minimal example for SageTeX:

x = 16 420       # Denominator
MyRange = 100
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:

image description

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}