Ask Your Question
1

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

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

bentheteacher gravatar image

updated 2018-07-25 01:09:17 +0200

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-25 01:14:47 +0200

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

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

slelievre gravatar imageslelievre ( 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)}$.

Juanjo gravatar imageJuanjo ( 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

Question Tools

Stats

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

Seen: 730 times

Last updated: Jul 25 '18