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

workflow for including code #28

Open
jlapeyre opened this issue Nov 29, 2020 · 2 comments
Open

workflow for including code #28

jlapeyre opened this issue Nov 29, 2020 · 2 comments

Comments

@jlapeyre
Copy link

What is a good method for displaying code in a document and then using it in a juliaconsole block?
The following seems to work, but I suspect there is a simpler way.

\begin{example}
\begin{juliablock}
some code
\end{juliablock}
\caption{example code}
\end{example}

Then I copy the code in the juliablock by hand into a file called example_code.jl.
Then I do this:

\begin{juliaconsole}
include("example_code.jl"); nothing
... use code...
\end{juliaconsole}
@tawheeler
Copy link
Collaborator

In our book we have a custom script that takes any code in a juliaverbatim block and puts it into a Julia package source file. We add a jlcode block that loads this package:

\begin{jlcode}
using OurPackage
\end{jlcode}

You could do something similar. The pythontex docs state that the pyconcode will execute but typeset nothing, so maybe jlconcode could be used to load the package prior to your juliaconsole block:

\begin{jlconcode}
using YourPackage
\end{jlconcode}
\begin{juliaconsole}
... use code ...
\end{juliaconsole}

There is an optional session id parameter as well. I think it defaults to a single session, but it may need to be specified.

@mykelk
Copy link
Member

mykelk commented Nov 30, 2020

I think @mossr has some experience with this.

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

3 participants