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

unexpected behavior when table cell ends with a latex space "\ " #2308

Closed
3 tasks done
mjsmith037 opened this issue Dec 4, 2023 · 3 comments
Closed
3 tasks done

unexpected behavior when table cell ends with a latex space "\ " #2308

mjsmith037 opened this issue Dec 4, 2023 · 3 comments
Assignees
Labels
bug Bugs

Comments

@mjsmith037
Copy link

Describe the bug

When a table cell ends with an explicit space, specified in latex as "\ ", kable inappropriately prunes the space, resulting in erroneous latex code that cannot be compiled.

To reproduce

library(knitr)
kable(data.frame(x="\\ "), format="latex", escape=FALSE)

produces:

\begin{tabular}{l}
\hline
x\\
\hline
\\\
\hline
\end{tabular}

Note that line 5 of the output should be "\ \\" (with a space between the first and second backslashes).

When attempting to compile this, an erroneous .pdf is produced:

test.pdf

Session info

xfun::session_info('knitr')
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 20.3, RStudio 2023.9.0.463


Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
  LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/Chicago
tzcode source: system (glibc)

Package version:
  evaluate_0.21   graphics_4.3.0  grDevices_4.3.0 highr_0.10      knitr_1.43      methods_4.3.0   stats_4.3.0     tools_4.3.0    
  utils_4.3.0     xfun_0.39       yaml_2.3.7  

Note this issue was previously, erroneously posted in the kableExtra repo.


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@cderv
Copy link
Collaborator

cderv commented Dec 5, 2023

Yes I believe we are trimming whitespace, no matter the escape settings... 🤔

knitr/R/table.R

Line 156 in 4b47d2a

x = trimws(x)

@yihui do you think we could have some specific handling in some case ? Either trimming when escape = TRUE only ?

with additional check on whitespace espace sequence depending on format ? 🤔

Or maybe we need a specific marked string to not trim....

Like

data.frame(x=I("\\ "))

@cderv cderv added the bug Bugs label Dec 5, 2023
@yihui yihui closed this as completed in 076f2c7 Dec 5, 2023
@yihui
Copy link
Owner

yihui commented Dec 5, 2023

Trailing spaces escaped by \ are no longer trimmed. Thanks!

Copy link

github-actions bot commented Jun 5, 2024

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs
Projects
None yet
Development

No branches or pull requests

3 participants