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

Allow code cell output to be read as raw text by latex processor #4

Open
amichuda opened this issue Nov 10, 2020 · 8 comments
Open
Labels
enhancement New feature or request

Comments

@amichuda
Copy link

amichuda commented Nov 10, 2020

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?

@amichuda amichuda added the enhancement New feature or request label Nov 10, 2020
@AakashGfude
Copy link
Member

Aah, nice. thanks for testing this one out @amichuda . I will add this to my list of tasks.

@amichuda
Copy link
Author

amichuda commented Jan 21, 2021

Thinking about this a bit more, wouldn't this require a special node myst-nb?

executablebooks/MyST-NB#295

@AakashGfude
Copy link
Member

AakashGfude commented Jan 25, 2021

@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 executablebooks/MyST-NB#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.

@amichuda
Copy link
Author

amichuda commented Jan 25, 2021

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}

@AakashGfude
Copy link
Member

yes, I do have created a post-transform to detect latex code. let me try doubling the backslashes and see. Thank you.

@amichuda
Copy link
Author

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!

@AakashGfude
Copy link
Member

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. :)

@mmcky
Copy link
Member

mmcky commented Jun 2, 2021

@AakashGfude is this still an open issue?

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

No branches or pull requests

3 participants