From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Bernt's document and LaTeX [was: Re: http://doc.norang.ca/org-mode.html ] Date: Mon, 08 Jun 2009 20:41:14 -0400 Message-ID: <9308.1244508074@gamaville.dokosmarshall.org> References: <26E81FB3-E33C-472C-B5B3-9548B0554B68@gmail.com> Reply-To: nicholas.dokos@hp.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MDpQ4-0005MA-RE for emacs-orgmode@gnu.org; Mon, 08 Jun 2009 20:42:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MDpQ3-0005Ly-Ve for emacs-orgmode@gnu.org; Mon, 08 Jun 2009 20:42:28 -0400 Received: from [199.232.76.173] (port=34483 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MDpQ3-0005Lv-Qs for emacs-orgmode@gnu.org; Mon, 08 Jun 2009 20:42:27 -0400 Received: from qmta10.emeryville.ca.mail.comcast.net ([76.96.30.17]:41770) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MDpQ3-00043O-69 for emacs-orgmode@gnu.org; Mon, 08 Jun 2009 20:42:27 -0400 In-Reply-To: Message from Carsten Dominik of "Mon\, 08 Jun 2009 22\:59\:47 +0200." <26E81FB3-E33C-472C-B5B3-9548B0554B68@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Carsten Dominik Cc: emacs-orgmode mailing list Carsten Dominik wrote: > I would like to encourage you all to take another looks at Bernt's > nearly completed document over at >=20 > http://doc.norang.ca/org-mode.html >=20 > If you are serious about using Org-mode to get organized, this > is simply an awesome resource of ideas, customization snippets, > tips and tricks. I am learning looking at that, too. >=20 > Thanks for doing this, Bernt. >=20 Seconded, thirded and fourthed: thanks Bernt! And while we are on the subject of Bernt's document: I haven't looked at the most recent incarnation on Bernt's website, but I got his org file from worg the other day and I tried to export it to LaTeX/PDF and print a copy to read (I prefer paper for documents that I'd like to read carefully - in this case, I can also put the printed document under my pillow: I hear it's the only way for hopeless cases like me to get organized !-) But I ran into a problem with the LaTeX exporter. Bernt uses code emphasis in a bunch of places, e.g. with TODO keywords, like the following: ,---- | *** Normal Task States | Normal tasks go through the sequence =3DTODO=3D -> =3DSTARTED=3D -> =3DDO= NE=3D. | The second sequence is really just a convenient collection of odd-ball | states for tasks (=3DWAITING=3D, =3DSOMEDAY=3D, =3DCANCELLED=3D). `---- but also in headings, like this: ,---- | *** Using =3DSTARTED=3D for clocked tasks | Tasks automatically change to =3DSTARTED=3D whenever they are clocked= in. `---- The LaTeX exporter turns these into the following: ,---- | \subsubsection{Normal Task States} | \label{sec-3.1.1} |=20 | Normal tasks go through the sequence \verb~TODO~ -> \verb~STARTED~ -> \ve= rb~DONE~. | The second sequence is really just a convenient collection of odd-ball | states for tasks (\verb~WAITING~, \verb~SOMEDAY~, \verb~CANCELLED~). `---- and ,---- | \subsubsection{Using \verb~STARTED~ for clocked tasks} | \label{sec-3.3.1} |=20 | Tasks automatically change to \verb~STARTED~ whenever they are clocke= d in. `---- But \verb is a "fragile" command and cannot be used in a moving argument (e.g. a subsubsection heading - it's a "moving" argument because it's going to be "moved around" on its way to the table of contents and its expansion has to be timed correctly), so LaTeX complains about the \verb in the \subsubsection title above. The standard way to deal with this problem is to \protect the fragile command: use \protect\verb instead of \verb in the moving argument. I did something simpler: I tweaked the exporter to \protect every \verb - afaik, this might be inefficient, but it should not cause a problem. I did that with the following patch: --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -1377,7 +1385,7 @@ The conversion is made depending of STRING-BEFORE and= STRING-AFTER." (if (not (string-match (regexp-quote (substring ll i (1+ i))) string)) (progn - (setq format (concat "\\verb" (substring ll i (1+ i)) + (setq format (concat "\\protect\\verb" (substring ll i (1+ i)) "%s" (substring ll i (1+ i)))) (throw 'exit nil)))))))) (setq string (org-export-latex-protect-string The resulting LaTeX document has every \verb properly (NOT!) \protect'ed. But LaTeX sure does not like the result: ,---- | This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6) (format=3Dpdflatex= 2009.2.9) 8 JUN 2009 18:17 | entering extended mode | %&-line parsing enabled. | **org-mode.tex | (./org-mode.tex | LaTeX2e <2005/12/01> | Babel and hyphenation patterns for english, usenglishmax, dumylan= g, noh | yphenation, pinyin, loaded. | (/usr/share/texmf-texlive/tex/latex/base/article.cls | Document Class: article 2005/09/16 v1.4f Standard LaTeX document class |=20 | ....lots of stuff elided .... |=20 | [15] [16] [17] | Runaway argument? | the \protect \relax \hbox {}#I\catcode `\ \active \-command \csname\= endcsn | ame | ! Paragraph ended before \HyPsd@@ProtectSpaces was complete. | =20 | \par=20 | l.918 ...ct\verb~STARTED~ task list under control} |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20 | ? `---- The funny thing is that there are four instances of this construct in Bernt's document: ,---- | ... | \subsubsection{Using \protect\verb~STARTED~ for clocked tasks} | ... | \subsubsection{Why keep it all on the \protect\verb~STARTED~ list?} | ... | \subsection{Keeping the \protect\verb~STARTED~ task list under control} | ... | \subsubsection{\textbf{UNFINISHED} Using \protect\verb~f5~} | ... `---- and it's only the third one that causes a problem: if I get rid of the markup on that one, pdfLaTeX finishes normally. Aha! I noted that the probl= em is a \subsection argument, whereas the others are \subsubsection arguments - the former appears in the TOC, whereas the latter do not by default - but if I change the \tocdepth from the default 2 to 3, then subsu= bsections get added to the table of contents and then LaTeX barfs on those too: \prot= ect is a bust. After doing a little research, I found out that \verb is not just "fragile": it's *special* (see e.g. http://www.tex.ac.uk/cgi-bin/texfaq2html?label=3Dv= erbwithin where I find: This is why the LaTeX book insists that verbatim commands must not appear in the argument of any other command; they aren=E2=80=99t just fragile, they=E2=80=99re quite unusable in any command parameter, regardless of \protection. (The \verb command tries hard to detect if you=E2=80=99re misusing it; unfortunately, it can=E2=80=99t always= do so, and the error message is therefore not a reliable indication of problems.) The suggested workaround is to actually use \texttt{foo}, instead of \verb~foo~ where the two would give identical results. This has problems of its own: the main one is things like underscores which would need to be escaped. But I wonder if the LaTeX exporter should go this way, rather than fighting with \verb all the way (and losing). Or if we can distinguish between body instances and section heading instances, do the \texttt{foo} transformation only on the latter. Comments? Thanks, Nick