Hello,
** Jon Degenhardt [2014-01-11 13:18:29 -0800]:

> Export to Latex (org-latex-export-to-pdf) generates incorrect latex when
> list items start with a left square bracket. This occurs because the
> \item command interprets the left square bracket as the start of an
> argument list. An example:

>    An item list:
>    - abc def
>    - [def] ghi
>    - [jkl m n o]
>    - pqr

> This produces the latex fragment:

>    An item list:
>    \begin{itemize}
>    \item abc def
>    \item [def] ghi
>    \item [jkl m n o]
>    \item pqr
>    \end{itemize}

> The pdf output renders the second and third items incorrectly. If there
> is no right bracket to terminate the argument, then pdf generation may
> fail with message:
>   
>    org-latex-compile: PDF file ./example.pdf wasn't produced: Runaway argument

This is (mis-)feature of LaTeX itemize and enumerate environments.  The
most simple way to "correct" output is to put '\relax' right after
'\item' or output for these environments '\item[]' instead of solely '\item'.

> I fixed these cases in my local environment using defadvise on org-latex-item
> to wrap an initial left square bracket in braces. I used this form:

>    (eval-after-load "ox-latex"
>      '(progn
>         (defadvice org-latex-item (after escape-initial-bracket activate)
>           (setq ad-return-value
>                 (replace-regexp-in-string 
>                     "\\\\item \\[" 
>                     "\\\\item {[}" 
>                     ad-return-value)))))

> This changes the latex fragment for the above example to:

>    An item list:
>    \begin{itemize}
>    \item abc def
>    \item {[}def] ghi
>    \item {[}jkl m n o]
>    \item pqr
>    \end{itemize}

> This form renders PDF correctly. My knowledge of latex is very limited,
> I don't know if this is a reasonable approach or not. There appears to
> be one other function in the ox-latex.el generating the \item command:
> (org-latex-headline). I did not try to reproduce this case.

[...]

FWIW, itemize and enumerate environments are built on top of \list
command, as well as 'description' environment. But only last environment
uses 'optional' arguments for '\item', the first two shouldn't have such
option. Unfortunately, there is only one '\item' command, that is used in all
three environments. It is impossible to redefine "kernel" environments
itemize and enumerate to work properly with '[]' after item, but some
LaTeX packages could 'patch' standard environments to 'fix' the issue,
for example, 'enumitem' package.

---
WBR, Vladimir Lomov

-- 
In an age when the fashion is to be in love with yourself, confessing to
be in love with somebody else is an admission of unfaithfulness to one's
beloved.
                -- Russell Baker

Reply via email to