# Is there a way to use sage-boolean-values in Latex

Hey there,

im completely new to sage and so far i got along quite well, but i can't figure this one out. I want to create randomized mathproblems and i want latex to decide what to print depending on calculations in sage.

So here is a functional minimal example:

\documentclass{article}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
a = ZZ.random_element(1,20)
b = ZZ.random_element(1,20)
\end{sagesilent}
$\sage{a}-\sage{b}$
\end{document}


What do i need to do if i want to switch a and b depending on if the result is negative or not?

edit retag close merge delete

Sort by ยป oldest newest most voted

As a workaround, one could do the following:

\documentclass{article}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
a = ZZ.random_element(1,20)
b = ZZ.random_element(1,20)
if a < b:
a, b = b, a
\end{sagesilent}
$\sage{a}-\sage{b}$
\end{document}

more

Thanks for your answer. I already got to that workaround myself in the meantime.

So the bottom line for this kind of problem is:

Do all the logic in python right? :)

( 2018-07-31 10:24:11 -0600 )edit

Given the choice of programming in Python or in LaTeX, I know which one I'll choose. : )

( 2018-08-05 17:28:36 -0600 )edit

In fact, there is no need to switch a and b. You can simply write $\sage{max(a,b)}-\sage{min(a,b)}$.

( 2019-02-20 09:02:01 -0600 )edit