git.iko.soy/typeable/pandoc
on master help sign in
Improved texorpdfstring patch #1148.

* Make LaTeX reader recognize texorpdfstring. * Don't use texorpdfstring unless it's actually needed. * Fix tests.

commit47c360e0795a5f27e4906ea22fff388b779f270a authorJohn MacFarlane <jgm@berkeley.edu> dateMon 15 Dec 2014, 10:03 (12 years ago) parent544f3e5
6 files changed+38−40
src/Text/Pandoc/Readers/LaTeX.hs+1 src/Text/Pandoc/Writers/LaTeX.hs+6−3 tests/Tests/Writers/LaTeX.hs+1−1 tests/lhs-test.latex+1−1 tests/lhs-test.latex+lhs+1−1 tests/writer.latex+28−34
src/Text/Pandoc/Readers/LaTeX.hs+1
@@ -417,6 +417,7 @@ inlineCommands = M.fromList $
417417 , ("(", mathInline $ manyTill anyChar (try $ string "\\)"))
418418 , ("[", mathDisplay $ manyTill anyChar (try $ string "\\]"))
419419 , ("ensuremath", mathInline $ braced)
420+ , ("texorpdfstring", (\_ x -> x) <$> tok <*> tok)
420421 , ("P", lit "¶")
421422 , ("S", lit "§")
422423 , ("$", lit "$")
src/Text/Pandoc/Writers/LaTeX.hs+6−3
@@ -626,9 +626,12 @@ sectionHeader unnumbered ref level lst = do
626626 then return empty
627627 else do
628628 return $ brackets txtNoNotes
629− let stuffing = star <> optional <> braces (text "\\texorpdfstring"
630− <> braces txt
631− <> braces (text plain))
629+ let contents = if render Nothing txt == plain
630+ then braces txt
631+ else braces (text "\\texorpdfstring"
632+ <> braces txt
633+ <> braces (text plain))
634+ let stuffing = star <> optional <> contents
632635 book <- gets stBook
633636 opts <- gets stOptions
634637 let level' = if book || writerChapters opts then level - 1 else level
tests/Tests/Writers/LaTeX.hs+1−1
@@ -62,7 +62,7 @@ tests = [ testGroup "code blocks"
6262 "\\begin{description}\n\\item[foo] ~ \n\\subsection{bar}\n\nbaz\n\\end{description}"
6363 , "containing image" =:
6464 header 1 (image "imgs/foo.jpg" "" (text "Alt text")) =?>
65− "\\section{\\protect\\includegraphics{imgs/foo.jpg}}"
65+ "\\section{\\texorpdfstring{\\protect\\includegraphics{imgs/foo.jpg}}{Alt text}}"
6666 ]
6767 , testGroup "inline code"
6868 [ "struck out and highlighted" =:
tests/lhs-test.latex+1−1
@@ -70,7 +70,7 @@
7070
7171\begin{document}
7272
73−\section{\texorpdfstring{lhs test}{lhs test}}\label{lhs-test}
73+\section{lhs test}\label{lhs-test}
7474
7575\texttt{unsplit} is an arrow that takes a pair of values and combines them to
7676return a single value:
tests/lhs-test.latex+lhs+1−1
@@ -51,7 +51,7 @@
5151
5252\begin{document}
5353
54−\section{\texorpdfstring{lhs test}{lhs test}}\label{lhs-test}
54+\section{lhs test}\label{lhs-test}
5555
5656\texttt{unsplit} is an arrow that takes a pair of values and combines them to
5757return a single value:
tests/writer.latex+28−34
@@ -72,7 +72,7 @@ markdown test suite.
7272
7373\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
7474
75−\section{\texorpdfstring{Headers}{Headers}}\label{headers}
75+\section{Headers}\label{headers}
7676
7777\subsection{\texorpdfstring{Level 2 with an \href{/url}{embedded
7878link}}{Level 2 with an embedded link}}\label{level-2-with-an-embedded-link}
@@ -80,26 +80,26 @@ link}}{Level 2 with an embedded link}}\label{level-2-with-an-embedded-link}
8080\subsubsection{\texorpdfstring{Level 3 with
8181\emph{emphasis}}{Level 3 with emphasis}}\label{level-3-with-emphasis}
8282
83−\paragraph{\texorpdfstring{Level 4}{Level 4}}\label{level-4}
83+\paragraph{Level 4}\label{level-4}
8484
85−\subparagraph{\texorpdfstring{Level 5}{Level 5}}\label{level-5}
85+\subparagraph{Level 5}\label{level-5}
8686
87−\section{\texorpdfstring{Level 1}{Level 1}}\label{level-1}
87+\section{Level 1}\label{level-1}
8888
8989\subsection{\texorpdfstring{Level 2 with
9090\emph{emphasis}}{Level 2 with emphasis}}\label{level-2-with-emphasis}
9191
92−\subsubsection{\texorpdfstring{Level 3}{Level 3}}\label{level-3}
92+\subsubsection{Level 3}\label{level-3}
9393
9494with no blank line
9595
96−\subsection{\texorpdfstring{Level 2}{Level 2}}\label{level-2}
96+\subsection{Level 2}\label{level-2}
9797
9898with no blank line
9999
100100\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
101101
102−\section{\texorpdfstring{Paragraphs}{Paragraphs}}\label{paragraphs}
102+\section{Paragraphs}\label{paragraphs}
103103
104104Here's a regular paragraph.
105105
@@ -113,7 +113,7 @@ There should be a hard line break\\here.
113113
114114\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
115115
116−\section{\texorpdfstring{Block Quotes}{Block Quotes}}\label{block-quotes}
116+\section{Block Quotes}\label{block-quotes}
117117
118118E-mail style:
119119
@@ -158,7 +158,7 @@ And a following paragraph.
158158
159159\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
160160
161−\section{\texorpdfstring{Code Blocks}{Code Blocks}}\label{code-blocks}
161+\section{Code Blocks}\label{code-blocks}
162162
163163Code:
164164
@@ -182,9 +182,9 @@ These should not be escaped: \$ \\ \> \[ \{
182182
183183\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
184184
185−\section{\texorpdfstring{Lists}{Lists}}\label{lists}
185+\section{Lists}\label{lists}
186186
187−\subsection{\texorpdfstring{Unordered}{Unordered}}\label{unordered}
187+\subsection{Unordered}\label{unordered}
188188
189189Asterisks tight:
190190
@@ -255,7 +255,7 @@ Minuses loose:
255255 Minus 3
256256\end{itemize}
257257
258−\subsection{\texorpdfstring{Ordered}{Ordered}}\label{ordered}
258+\subsection{Ordered}\label{ordered}
259259
260260Tight:
261261
@@ -321,7 +321,7 @@ Multiple paragraphs:
321321 Item 3.
322322\end{enumerate}
323323
324−\subsection{\texorpdfstring{Nested}{Nested}}\label{nested}
324+\subsection{Nested}\label{nested}
325325
326326\begin{itemize}
327327\itemsep1pt\parskip0pt\parsep0pt
@@ -386,8 +386,7 @@ Same thing but with paragraphs:
386386 Third
387387\end{enumerate}
388388
389−\subsection{\texorpdfstring{Tabs and
390−spaces}{Tabs and spaces}}\label{tabs-and-spaces}
389+\subsection{Tabs and spaces}\label{tabs-and-spaces}
391390
392391\begin{itemize}
393392\item
@@ -403,8 +402,7 @@ spaces}{Tabs and spaces}}\label{tabs-and-spaces}
403402 \end{itemize}
404403\end{itemize}
405404
406−\subsection{\texorpdfstring{Fancy list
407−markers}{Fancy list markers}}\label{fancy-list-markers}
405+\subsection{Fancy list markers}\label{fancy-list-markers}
408406
409407\begin{enumerate}
410408\def\labelenumi{(\arabic{enumi})}
@@ -492,8 +490,7 @@ B. Williams
492490
493491\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
494492
495−\section{\texorpdfstring{Definition
496−Lists}{Definition Lists}}\label{definition-lists}
493+\section{Definition Lists}\label{definition-lists}
497494
498495Tight using spaces:
499496
@@ -596,7 +593,7 @@ orange fruit
596593\end{enumerate}
597594\end{description}
598595
599−\section{\texorpdfstring{HTML Blocks}{HTML Blocks}}\label{html-blocks}
596+\section{HTML Blocks}\label{html-blocks}
600597
601598Simple block on one line:
602599
@@ -658,7 +655,7 @@ Hr's:
658655
659656\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
660657
661−\section{\texorpdfstring{Inline Markup}{Inline Markup}}\label{inline-markup}
658+\section{Inline Markup}\label{inline-markup}
662659
663660This is \emph{emphasized}, and so \emph{is this}.
664661
@@ -690,8 +687,7 @@ spaces: a\^{}b c\^{}d, a\textasciitilde{}b c\textasciitilde{}d.
690687
691688\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
692689
693−\section{\texorpdfstring{Smart quotes, ellipses,
694−dashes}{Smart quotes, ellipses, dashes}}\label{smart-quotes-ellipses-dashes}
690+\section{Smart quotes, ellipses, dashes}\label{smart-quotes-ellipses-dashes}
695691
696692``Hello,'' said the spider. ``\,`Shelob' is my name.''
697693
@@ -712,7 +708,7 @@ Ellipses\ldots{}and\ldots{}and\ldots{}.
712708
713709\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
714710
715−\section{\texorpdfstring{LaTeX}{LaTeX}}\label{latex}
711+\section{LaTeX}\label{latex}
716712
717713\begin{itemize}
718714\itemsep1pt\parskip0pt\parsep0pt
@@ -760,8 +756,7 @@ Cat & 1 \\ \hline
760756
761757\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
762758
763−\section{\texorpdfstring{Special
764−Characters}{Special Characters}}\label{special-characters}
759+\section{Special Characters}\label{special-characters}
765760
766761Here is some unicode:
767762
@@ -823,9 +818,9 @@ Minus: -
823818
824819\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
825820
826−\section{\texorpdfstring{Links}{Links}}\label{links}
821+\section{Links}\label{links}
827822
828−\subsection{\texorpdfstring{Explicit}{Explicit}}\label{explicit}
823+\subsection{Explicit}\label{explicit}
829824
830825Just a \href{/url/}{URL}.
831826
@@ -845,7 +840,7 @@ Just a \href{/url/}{URL}.
845840
846841\href{}{Empty}.
847842
848−\subsection{\texorpdfstring{Reference}{Reference}}\label{reference}
843+\subsection{Reference}\label{reference}
849844
850845Foo \href{/url/}{bar}.
851846
@@ -873,8 +868,7 @@ Foo \href{/url/}{bar}.
873868
874869Foo \href{/url/}{biz}.
875870
876−\subsection{\texorpdfstring{With
877−ampersands}{With ampersands}}\label{with-ampersands}
871+\subsection{With ampersands}\label{with-ampersands}
878872
879873Here's a \href{http://example.com/?foo=1\&bar=2}{link with an ampersand in the
880874URL}.
@@ -886,7 +880,7 @@ Here's an \href{/script?foo=1\&bar=2}{inline link}.
886880
887881Here's an \href{/script?foo=1\&bar=2}{inline link in pointy braces}.
888882
889−\subsection{\texorpdfstring{Autolinks}{Autolinks}}\label{autolinks}
883+\subsection{Autolinks}\label{autolinks}
890884
891885With an ampersand: \url{http://example.com/?foo=1\&bar=2}
892886
@@ -916,7 +910,7 @@ or here: <http://example.com/>
916910
917911\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
918912
919−\section{\texorpdfstring{Images}{Images}}\label{images}
913+\section{Images}\label{images}
920914
921915From ``Voyage dans la Lune'' by Georges Melies (1902):
922916
@@ -930,7 +924,7 @@ Here is a movie \includegraphics{movie.jpg} icon.
930924
931925\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
932926
933−\section{\texorpdfstring{Footnotes}{Footnotes}}\label{footnotes}
927+\section{Footnotes}\label{footnotes}
934928
935929Here is a footnote reference,\footnote{Here is the footnote. It can go
936930 anywhere after the footnote reference. It need not be placed at the end of