You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a user specifies a cols_width() value using the pct() function and tries to render to PDF, the render will fail with an error at the LaTeX compile stage (exact line number of the error depends on document content):
compilation failed- error
Paragraph ended before \scr@LT@array was complete.
<to be read again>
\par
l.195
Expected Behavior
Using a pct() call to specify column widths with cols_width() when outputting to LaTeX/PDF should not produce an error.
Actual Behavior
The resulting knitted document produces an error at the LaTeX compilation stage.
Minimal Reproducible R Script
Compiling this script as its own file should produce the LaTeX error.
Also, by preserving LaTeX output we can visually inspect the generated LaTeX.
We can see from the LaTeX above that the % is causing all characters following it to be treated as a comment, rather than executable LaTeX.
Tracing the Problem through gt
When a user specifies a percentage with pct() inside a cols_width() call, the pct() call just takes that number and converts it into a string by concatenating a raw % to the number.
That string value---which includes the raw % sign, gets passed to create_table_start_l(). On line 175 of that function, if the value of col_widths[i] isn't null, we eventually move to line 186, where col_widths[i] gets pasted in seemingly without any check as to whether it contains a raw % sign.
At this point col_widths[i] will necessarily contain the raw percent sign. So...
The resulting text: "p{", col_widths[i], "}" gets passed on to LaTeX, where the LaTeX compiler interprets anything following an unescaped % as a comment.
The call to p{} in LaTeX never gets a closing brace, because of the comment symbol.
LaTeX fails to compile the document.
A Temporary Work-Around
Instead of calling pct(), a user can specify a string literal with a backslash-escaped %, as in this fully reproducible script
Replaces the use of percentage symbols to express column widths, which cause an error when compiling Latex, with column widths that are expressed as a share of `\linewidth` or the user-supplied `table_width`.
Replaces the use of percentage symbols to express column widths, which cause an error when compiling Latex, with column widths that are expressed as a share of `\linewidth` or the user-supplied `table_width`.
The Problem
If a user specifies a
cols_width()
value using thepct()
function and tries to render to PDF, the render will fail with an error at the LaTeX compile stage (exact line number of the error depends on document content):Expected Behavior
Using a
pct()
call to specify column widths withcols_width()
when outputting to LaTeX/PDF should not produce an error.Actual Behavior
The resulting knitted document produces an error at the LaTeX compilation stage.
Minimal Reproducible R Script
Compiling this script as its own file should produce the LaTeX error.
Also, by preserving LaTeX output we can visually inspect the generated LaTeX.
The Offending LaTeX Lines
We can see from the LaTeX above that the
%
is causing all characters following it to be treated as a comment, rather than executable LaTeX.Tracing the Problem through
gt
pct()
inside acols_width()
call, thepct()
call just takes that number and converts it into a string by concatenating a raw%
to the number.%
sign, gets passed tocreate_table_start_l()
. On line 175 of that function, if the value ofcol_widths[i]
isn't null, we eventually move to line 186, wherecol_widths[i]
gets pasted in seemingly without any check as to whether it contains a raw%
sign.col_widths[i]
will necessarily contain the raw percent sign. So..."p{", col_widths[i], "}"
gets passed on to LaTeX, where the LaTeX compiler interprets anything following an unescaped%
as a comment.p{}
in LaTeX never gets a closing brace, because of the comment symbol.A Temporary Work-Around
Instead of calling
pct()
, a user can specify a string literal with a backslash-escaped%
, as in this fully reproducible scriptSession Info
The text was updated successfully, but these errors were encountered: