* very strange LaTeX error
@ 2019-12-20 11:56 Fraga, Eric
2019-12-20 12:33 ` Joost Kremers
0 siblings, 1 reply; 7+ messages in thread
From: Fraga, Eric @ 2019-12-20 11:56 UTC (permalink / raw)
To: Emacs Org mode mailing list
Hello all,
this may not belong in this mailing list as it's arguably a LaTeX issue
but I'm having a problem exporting a table to PDF via LaTeX. I hope
somebody can help me out.
I've reduced my problem file to a small (hopefully minimal) example and
verified this with emacs -Q, using emacs 27.x which comes with org 9.3:
#+begin_src org
,* some results
,#+name: atable
|------------------------------------+----------+----------------------+-----|
| x | z1 | z2 | g |
|------------------------------------+----------+----------------------+-----|
| [0.0005, 0.05, 0.5] | 90000.0 | 0.05 | 0.0 |
| [0.000787451, 0.0575948, 0.5] | 110000.0 | 0.05759476698672508 | 0.0 |
|------------------------------------+----------+----------------------+-----|
#+end_src
If I export this to LaTeX, I get something that looks reasonable (elided):
#+begin_src latex
\documentclass{scrartcl}
\begin{document}
% packages deleted, none of which is used anyway in the following
\tableofcontents
\section{some results}
\label{sec:org4f5891c}
\begin{table}[hbtp]
\label{atable}
\centering
\begin{tabular}{lrrr}
\hline
x & z1 & z2 & g\\
\hline
[0.0005, 0.05, 0.5] & 90000.0 & 0.05 & 0.0\\
[0.000787451, 0.0575948, 0.5] & 110000.0 & 0.05759476698672508 & 0.0\\
\hline
\end{tabular}
\end{table}
\end{document}
#+end_src
I get errors like this when compiling with pdflatex:
#+begin_example
! Illegal unit of measure (pt inserted).
<to be read again>
,
l.18 [0.000787451, 0.0575948, 0.5]
& 110000.0 & 0.05759476698672508 & 0.0\\
! Missing = inserted for \ifdim.
<to be read again>
#+end_example
What am I doing wrong? If LaTeX cannot handle [...] in a table (it has
no problem with similar text in a normal paragraph), the LaTeX exporter
should do something about this. But I do not see why LaTeX should have
a problem in any case. Any pointers welcome!
Note: LaTeX does not complain about the first line in the table, only
the second (and following ones in the original org file from which I
took this code snippet).
Thank you.
--
Eric S Fraga via Emacs 27.0.50, Org release_9.3-34-g2eee3c
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: very strange LaTeX error
2019-12-20 11:56 very strange LaTeX error Fraga, Eric
@ 2019-12-20 12:33 ` Joost Kremers
2019-12-20 14:29 ` Stefan Nobis
2019-12-20 14:48 ` Fraga, Eric
0 siblings, 2 replies; 7+ messages in thread
From: Joost Kremers @ 2019-12-20 12:33 UTC (permalink / raw)
To: emacs-orgmode
On Fri, Dec 20, 2019, at 12:56 PM, Fraga, Eric wrote:
> #+begin_src latex
> \documentclass{scrartcl}
> \begin{document}
> % packages deleted, none of which is used anyway in the following
> \tableofcontents
>
> \section{some results}
> \label{sec:org4f5891c}
> \begin{table}[hbtp]
> \label{atable}
> \centering
> \begin{tabular}{lrrr}
> \hline
> x & z1 & z2 & g\\
> \hline
> [0.0005, 0.05, 0.5] & 90000.0 & 0.05 & 0.0\\
> [0.000787451, 0.0575948, 0.5] & 110000.0 & 0.05759476698672508 & 0.0\\
> \hline
> \end{tabular}
> \end{table}
> \end{document}
> #+end_src
>
> I get errors like this when compiling with pdflatex:
>
> #+begin_example
> ! Illegal unit of measure (pt inserted).
> <to be read again>
> ,
> l.18 [0.000787451, 0.0575948, 0.5]
> & 110000.0 & 0.05759476698672508 & 0.0\\
> ! Missing = inserted for \ifdim.
> <to be read again>
> #+end_example
>
> What am I doing wrong?
You have `[...]` in the first cell of a table row that is not the first row. Few people seem to realise that the double backslash `\\` in LaTeX is a macro that can actually take an optional argument, a measure specifying the height of the newline. So when a table row ends in `\\` (which is the normal case) and the next row starts with an opening bracket, LaTeX assumes it is looking at an optional argument and expects a measure, i.e., a number followed by one of the supported units.
The solution I usually opt for is to enclose the brackets in an additional set of braces: `{[...]}`. Whether Org export can and should automate that, I can't say.
HTH
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: very strange LaTeX error
2019-12-20 12:33 ` Joost Kremers
@ 2019-12-20 14:29 ` Stefan Nobis
2019-12-20 15:53 ` Fraga, Eric
2019-12-20 14:48 ` Fraga, Eric
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Nobis @ 2019-12-20 14:29 UTC (permalink / raw)
To: emacs-orgmode
"Joost Kremers" <joostkremers@fastmail.fm> writes:
> The solution I usually opt for is to enclose the brackets in an
> additional set of braces: `{[...]}`. Whether Org export can and
> should automate that, I can't say.
In the generated LaTeX adding a '\relax' (so each line ends with
'\\\relax') would be a another solution. The \relax ends the
macro-expansion and thus '\\' does not look further for optional
arguments.
As the org-table does not support all the fancy features of LaTeX
tables and the LaTeX row/line break is generated implicitly, I would
say the LaTeX export should always emit the additional \relax.
--
Until the next mail...,
Stefan.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: very strange LaTeX error
2019-12-20 14:29 ` Stefan Nobis
@ 2019-12-20 15:53 ` Fraga, Eric
2019-12-20 16:28 ` Stefan Nobis
0 siblings, 1 reply; 7+ messages in thread
From: Fraga, Eric @ 2019-12-20 15:53 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
On Friday, 20 Dec 2019 at 15:29, Stefan Nobis wrote:
> As the org-table does not support all the fancy features of LaTeX
> tables and the LaTeX row/line break is generated implicitly, I would
> say the LaTeX export should always emit the additional \relax.
I agree. I shouldn't have to be this aware of LaTeX idiosyncrasies to
export what looks like a straightforward table!
However, it seems that simply adding \relax does not work if there is an
\hline immediately following so the solution is not that
straightforward.
Thanks again,
eric
--
Eric S Fraga via Emacs 27.0.50, Org release_9.3-34-g2eee3c
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: very strange LaTeX error
2019-12-20 15:53 ` Fraga, Eric
@ 2019-12-20 16:28 ` Stefan Nobis
2019-12-20 16:36 ` Fraga, Eric
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Nobis @ 2019-12-20 16:28 UTC (permalink / raw)
To: emacs-orgmode
"Fraga, Eric" <e.fraga@ucl.ac.uk> writes:
> However, it seems that simply adding \relax does not work if there
> is an \hline immediately following so the solution is not that
> straightforward.
Hmmm... but it should be solvable. Maybe something along the lines of
this (rough sketch, I have next to no experience with the org code
base):
#+begin_src emacs-lisp
(defun org-latex--table-newline (table-row info)
(let ((next-el (org-export-get-next-element table-row info)))
(concat "\\\\"
(when (and next-el
(not (eq (org-element-property :type next-el) 'rule)))
"\\relax")
"\n")))
#+end_src
--
Until the next mail...,
Stefan.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: very strange LaTeX error
2019-12-20 12:33 ` Joost Kremers
2019-12-20 14:29 ` Stefan Nobis
@ 2019-12-20 14:48 ` Fraga, Eric
1 sibling, 0 replies; 7+ messages in thread
From: Fraga, Eric @ 2019-12-20 14:48 UTC (permalink / raw)
To: Joost Kremers; +Cc: emacs-orgmode@gnu.org
On Friday, 20 Dec 2019 at 13:33, Joost Kremers wrote:
> Few people seem to realise that the double backslash `\\` in LaTeX is
> a macro that can actually take an optional argument, a measure
> specifying the height of the newline.
Ah ha! That makes perfect sense. Thank you.
--
Eric S Fraga via Emacs 27.0.50, Org release_9.3-34-g2eee3c
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-12-20 16:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-20 11:56 very strange LaTeX error Fraga, Eric
2019-12-20 12:33 ` Joost Kremers
2019-12-20 14:29 ` Stefan Nobis
2019-12-20 15:53 ` Fraga, Eric
2019-12-20 16:28 ` Stefan Nobis
2019-12-20 16:36 ` Fraga, Eric
2019-12-20 14:48 ` Fraga, Eric
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.