Ask Your Question
1

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

asked 2018-07-24 16:13:31 -0600

bentheteacher gravatar image

updated 2018-07-24 18:09:17 -0600

slelievre gravatar image

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 flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
3

answered 2018-07-24 18:14:47 -0600

slelievre gravatar image

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}
edit flag offensive delete link 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? :)

bentheteacher gravatar imagebentheteacher ( 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. : )

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

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2018-07-24 16:13:31 -0600

Seen: 34 times

Last updated: Jul 24