Ask Your Question

# 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

## 1 Answer

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

## Comments

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 17:24:11 +0200 )edit

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

( 2018-08-06 00:28:36 +0200 )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 16:02:01 +0200 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2018-07-24 23:13:31 +0200

Seen: 830 times

Last updated: Jul 25 '18