Replace some commands and environments within a TeX document by evaluating code inside a jupyter kernel
Project description
TexSurgery
Replaces some commands and environments within a TeX document
by evaluating code inside a jupyter kernel
Start with this LaTeX code:
% Any jupyter kernel is available
\usepackage[sagemath]{texsurgery}
% Compatible with any other LaTeX package
\usepackage[bloc,completemulti]{automultiplechoice}
% Example of user macros
\providecommand{\abs}[1]{\lvert#1\rvert}
\newcommand{\R}{\mathbb{R}}
% TexSurgery can replace some \commands before pdflatex runs
\begin{minipage}{.85\linewidth}
Student: {\bf \name \; \surname}, \quad ID: {\bf \id}
\end{minipage}
\begin{question}{derivative-sin}
\qvariant{1} \qtags{derivative}
% TexSurgery will run code in a jupyter kernel
\begin{runsilent}
set_random_seed(\seed)
a = randint(2,10)
f = sin(a*x)
fd = f.derivative(x)
\end{runsilent}
% TexSurgery will eval code in a jupyter kernel
% and replace \eval{expr} with the output from the kernel
% \sage{expr} is just an alias for \eval{latex(expr)}
What is the first derivative of $\sage{f}$?
\begin{choices}
\correctchoice{$\sage{fd}$}
\wrongchoice{$\sage{fd*a}$}
\wrongchoice{$\sage{fd + a}$}
\end{choices}
\begin{explain}
\begin{run}
# TexSurgery will run code in the jupyter kernel
# and replace this environment with the full output
\end{run}
\end{explain}
\end{question}
and run this python
code:
student_vars = dict(name='Fulano', surname='de Tal', seed=1, id='314159')
ts = TexSurgery(tex_source).data_surgery(student_vars).code_surgery()
in order to transform it into this:
% Compatible with any other LaTeX package
\usepackage[bloc,completemulti]{automultiplechoice}
% Example of user macros
\providecommand{\abs}[1]{\lvert#1\rvert}
\newcommand{\R}{\mathbb{R}}
\begin{minipage}{.85\linewidth}
Student: {\bf Fulano \; de Tal}, \quad ID: {\bf 314159}
\end{minipage}
\begin{question}{derivative-sin}
\qvariant{1} \qtags{derivative}
What is the first derivative of $\sin\left(7 \, x\right)$?
\begin{choices}
\correctchoice{$7 \, \cos\left(7 \, x\right)$}
\wrongchoice{$49 \, \cos\left(7 \, x\right)$}
\wrongchoice{$7 \, \cos\left(7 \, x\right) + 7$}
\end{choices}
\begin{explain}
\begin{run}
# TexSurgery will run code in the jupyter kernel
# and replace this environment with the full output
\end{run}
\end{explain}
\end{question}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
texsurgery-0.0.2.tar.gz
(6.0 kB
view details)
Built Distribution
File details
Details for the file texsurgery-0.0.2.tar.gz
.
File metadata
- Download URL: texsurgery-0.0.2.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71ebd2eeafdacb7aeff84e237323884fc6c247cf30e0ab0aa635c47cec92675a |
|
MD5 | b767767c92b6df3ed92a2ac78b25b953 |
|
BLAKE2b-256 | 9f2407065adcdc04d8d03f4fcdfeff5aadf58af0dbe5fca526de7fd1f6e48415 |
File details
Details for the file texsurgery-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: texsurgery-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d78504661fadc76d99cfee68f75094f965b386918e401a5e84093c508f9ed9e |
|
MD5 | 5c2afb804b2456b95ac3e16f0c8f7cd2 |
|
BLAKE2b-256 | e94c4291163d4e90f60877e3fb07bc5650b7f61bb66cdeac7b0ecc4ea1d34041 |