sphinx-jupyterbook-latex
sphinx-jupyterbook-latex copied to clipboard
Allow code cell output to be read as raw text by latex processor
When printing raw latex code with python, such as:
from tabulate import tabulate
table = [["spam",42],["eggs",451],["bacon",0]]
headers = ["item", "qty"]
print(tabulate(table, headers, tablefmt="latex"))
Output:
\begin{tabular}{lr}
\hline
item & qty \\
\hline
spam & 42 \\
eggs & 451 \\
bacon & 0 \\
\hline
\end{tabular}
The output is treated as a code block when running jb build --builder pdflatex
, but Rmarkdown
, for example, you can allow the results to be read as raw text so that the latex processor can actually render the table.
Is something like that possible?
Aah, nice. thanks for testing this one out @amichuda . I will add this to my list of tasks.
Thinking about this a bit more, wouldn't this require a special node myst-nb
?
https://github.com/executablebooks/MyST-NB/issues/295
@amichuda was working on this a bit. the one major problem I faced was in Sphinx LaTex writer, which escapes characters, like \
with a \textbackslash{}
for example.
The above was converted to
\textbackslash{}begin\{tabular\}\{lr\}
\textbackslash{}hline
item \& qty \textbackslash{}\textbackslash{}
\textbackslash{}hline
spam \& 42 \textbackslash{}\textbackslash{}
eggs \& 451 \textbackslash{}\textbackslash{}
bacon \& 0 \textbackslash{}\textbackslash{}
\textbackslash{}hline
\textbackslash{}end\{tabular\}
not sure if the fix for https://github.com/executablebooks/MyST-NB/issues/117 is gonna take this into account. Maybe @chrisjsewell can shed some more light on this.
Else, the only option I could figure out to solve this was to handle it in the writing phase of literal_block
. Where I can check if the output is latex code, and then prevent these escape characters.
Thanks for looking into this! I wonder if this can also just be handled by putting doubling the backslashes when generating the table:
\\begin{tabular}{lr}
\\hline
item & qty \\\\
\\hline
spam & 42 \\\\
eggs & 451 \\\\
bacon & 0 \\\\
\\hline
\\end{tabular}
yes, I do have created a post-transform to detect latex code. let me try doubling the backslashes and see. Thank you.
Thank you so much! If this all works out I'm gonna add you and the jupyterbook team to the special thanks in my thesis!
Thank you so much! If this all works out I'm gonna add you and the jupyterbook team to the special thanks in my thesis!
wohoo. need to work extra hard on this one then. :)
@AakashGfude is this still an open issue?