Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use functions in REPL (juliaconsole environment) defined in juliaverbatim environment. #33

Open
JamieMair opened this issue Jan 15, 2022 · 2 comments

Comments

@JamieMair
Copy link

I have an algorithm defined as follows:

\begin{algorithm}
\begin{juliaverbatim}
function my_large_sum()
    s = 0
    for i=1:100000000000
        s += i
    end
    return s
end
\end{juliaverbatim}
\end{algorithm}

This algorithm is rendered correctly and I can use it in tests, but not in the console environment:

\begin{juliaconsole}
import BenchmarkTools: @btime;
@btime my_large_sum()
\end{juliaconsole}

Doing this produces the following:
image

How can I access these functions in the console space?

@JamieMair
Copy link
Author

A temporary fix I have found is to add the following to the top of the book.tex file:

\begin{juliaconcode}
include("support_code.jl")
\end{juliaconcode}

This isn't a proper solution, since this is included in the book, which is not what I want. Hopefully hiding it from the book will be an easy fix. I have tried wrapping it in an \ifx statement, but this removes it from the latex file and doesn't call the code.

@tawheeler
Copy link
Collaborator

Hello JamieMair.
The pythontex documentation states:
"Notice that there is not a command or environment for console content that
parallels the block command and environment. That is, there is not a command
or environment that both typesets and executes code in the console, but does not
show the output. This is intentional. In most cases, if you are going to use the
console, you should use it consistently, showing input and output together."

Unfortunately, as you have seen, there are cases where we do actually want to use the console without showing input and output together. This currently seems to require a change to pythontex to enable that functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants