git.iko.soy/typeable/pandoc
on master help sign in
Improved texorpdfstring patch #1148.
47c360eJohn MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+1
@@ -417,6 +417,7 @@ inlineCommands = M.fromList $
417 , ("(", mathInline $ manyTill anyChar (try $ string "\\)"))
417 , ("(", mathInline $ manyTill anyChar (try $ string "\\)"))
418 , ("[", mathDisplay $ manyTill anyChar (try $ string "\\]"))
418 , ("[", mathDisplay $ manyTill anyChar (try $ string "\\]"))
419 , ("ensuremath", mathInline $ braced)
419 , ("ensuremath", mathInline $ braced)
420+ , ("texorpdfstring", (\_ x -> x) <$> tok <*> tok)
420 , ("P", lit "¶")
421 , ("P", lit "¶")
421 , ("S", lit "§")
422 , ("S", lit "§")
422 , ("$", lit "$")
423 , ("$", lit "$")
src/Text/Pandoc/Writers/LaTeX.hs+6−3
@@ -626,9 +626,12 @@ sectionHeader unnumbered ref level lst = do
626 then return empty
626 then return empty
627 else do
627 else do
628 return $ brackets txtNoNotes
628 return $ brackets txtNoNotes
629+ let contents = if render Nothing txt == plain
630+ then braces txt
631+ else braces (text "\\texorpdfstring"
632+ <> braces txt
633+ <> braces (text plain))
629− let stuffing = star <> optional <> braces (text "\\texorpdfstring"
634+ let stuffing = star <> optional <> contents
630− <> braces txt
631− <> braces (text plain))
632 book <- gets stBook
635 book <- gets stBook
633 opts <- gets stOptions
636 opts <- gets stOptions
634 let level' = if book || writerChapters opts then level - 1 else level
637 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"
62 "\\begin{description}\n\\item[foo] ~ \n\\subsection{bar}\n\nbaz\n\\end{description}"
62 "\\begin{description}\n\\item[foo] ~ \n\\subsection{bar}\n\nbaz\n\\end{description}"
63 , "containing image" =:
63 , "containing image" =:
64 header 1 (image "imgs/foo.jpg" "" (text "Alt text")) =?>
64 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}}"
66 ]
66 ]
67 , testGroup "inline code"
67 , testGroup "inline code"
68 [ "struck out and highlighted" =:
68 [ "struck out and highlighted" =:
tests/lhs-test.latex+1−1
@@ -70,7 +70,7 @@
70
70
71\begin{document}
71\begin{document}
72
72
73−\section{\texorpdfstring{lhs test}{lhs test}}\label{lhs-test}
73+\section{lhs test}\label{lhs-test}
74
74
75\texttt{unsplit} is an arrow that takes a pair of values and combines them to
75\texttt{unsplit} is an arrow that takes a pair of values and combines them to
76return a single value:
76return a single value:
tests/lhs-test.latex+lhs+1−1
@@ -51,7 +51,7 @@
51
51
52\begin{document}
52\begin{document}
53
53
54−\section{\texorpdfstring{lhs test}{lhs test}}\label{lhs-test}
54+\section{lhs test}\label{lhs-test}
55
55
56\texttt{unsplit} is an arrow that takes a pair of values and combines them to
56\texttt{unsplit} is an arrow that takes a pair of values and combines them to
57return a single value:
57return a single value:
tests/writer.latex+28−34
@@ -72,7 +72,7 @@ markdown test suite.
72
72
73\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
73\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
74
74
75−\section{\texorpdfstring{Headers}{Headers}}\label{headers}
75+\section{Headers}\label{headers}
76
76
77\subsection{\texorpdfstring{Level 2 with an \href{/url}{embedded
77\subsection{\texorpdfstring{Level 2 with an \href{/url}{embedded
78link}}{Level 2 with an embedded link}}\label{level-2-with-an-embedded-link}
78link}}{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}
80\subsubsection{\texorpdfstring{Level 3 with
80\subsubsection{\texorpdfstring{Level 3 with
81\emph{emphasis}}{Level 3 with emphasis}}\label{level-3-with-emphasis}
81\emph{emphasis}}{Level 3 with emphasis}}\label{level-3-with-emphasis}
82
82
83−\paragraph{\texorpdfstring{Level 4}{Level 4}}\label{level-4}
83+\paragraph{Level 4}\label{level-4}
84
84
85−\subparagraph{\texorpdfstring{Level 5}{Level 5}}\label{level-5}
85+\subparagraph{Level 5}\label{level-5}
86
86
87−\section{\texorpdfstring{Level 1}{Level 1}}\label{level-1}
87+\section{Level 1}\label{level-1}
88
88
89\subsection{\texorpdfstring{Level 2 with
89\subsection{\texorpdfstring{Level 2 with
90\emph{emphasis}}{Level 2 with emphasis}}\label{level-2-with-emphasis}
90\emph{emphasis}}{Level 2 with emphasis}}\label{level-2-with-emphasis}
91
91
92−\subsubsection{\texorpdfstring{Level 3}{Level 3}}\label{level-3}
92+\subsubsection{Level 3}\label{level-3}
93
93
94with no blank line
94with no blank line
95
95
96−\subsection{\texorpdfstring{Level 2}{Level 2}}\label{level-2}
96+\subsection{Level 2}\label{level-2}
97
97
98with no blank line
98with no blank line
99
99
100\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
100\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
101
101
102−\section{\texorpdfstring{Paragraphs}{Paragraphs}}\label{paragraphs}
102+\section{Paragraphs}\label{paragraphs}
103
103
104Here's a regular paragraph.
104Here's a regular paragraph.
105
105
@@ -113,7 +113,7 @@ There should be a hard line break\\here.
113
113
114\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
114\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
115
115
116−\section{\texorpdfstring{Block Quotes}{Block Quotes}}\label{block-quotes}
116+\section{Block Quotes}\label{block-quotes}
117
117
118E-mail style:
118E-mail style:
119
119
@@ -158,7 +158,7 @@ And a following paragraph.
158
158
159\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
159\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
160
160
161−\section{\texorpdfstring{Code Blocks}{Code Blocks}}\label{code-blocks}
161+\section{Code Blocks}\label{code-blocks}
162
162
163Code:
163Code:
164
164
@@ -182,9 +182,9 @@ These should not be escaped: \$ \\ \> \[ \{
182
182
183\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
183\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
184
184
185−\section{\texorpdfstring{Lists}{Lists}}\label{lists}
185+\section{Lists}\label{lists}
186
186
187−\subsection{\texorpdfstring{Unordered}{Unordered}}\label{unordered}
187+\subsection{Unordered}\label{unordered}
188
188
189Asterisks tight:
189Asterisks tight:
190
190
@@ -255,7 +255,7 @@ Minuses loose:
255 Minus 3
255 Minus 3
256\end{itemize}
256\end{itemize}
257
257
258−\subsection{\texorpdfstring{Ordered}{Ordered}}\label{ordered}
258+\subsection{Ordered}\label{ordered}
259
259
260Tight:
260Tight:
261
261
@@ -321,7 +321,7 @@ Multiple paragraphs:
321 Item 3.
321 Item 3.
322\end{enumerate}
322\end{enumerate}
323
323
324−\subsection{\texorpdfstring{Nested}{Nested}}\label{nested}
324+\subsection{Nested}\label{nested}
325
325
326\begin{itemize}
326\begin{itemize}
327\itemsep1pt\parskip0pt\parsep0pt
327\itemsep1pt\parskip0pt\parsep0pt
@@ -386,8 +386,7 @@ Same thing but with paragraphs:
386 Third
386 Third
387\end{enumerate}
387\end{enumerate}
388
388
389−\subsection{\texorpdfstring{Tabs and
390−spaces}{Tabs and spaces}}\label{tabs-and-spaces}
389+\subsection{Tabs and spaces}\label{tabs-and-spaces}
391
390
392\begin{itemize}
391\begin{itemize}
393\item
392\item
@@ -403,8 +402,7 @@ spaces}{Tabs and spaces}}\label{tabs-and-spaces}
403 \end{itemize}
402 \end{itemize}
404\end{itemize}
403\end{itemize}
405
404
406−\subsection{\texorpdfstring{Fancy list
407−markers}{Fancy list markers}}\label{fancy-list-markers}
405+\subsection{Fancy list markers}\label{fancy-list-markers}
408
406
409\begin{enumerate}
407\begin{enumerate}
410\def\labelenumi{(\arabic{enumi})}
408\def\labelenumi{(\arabic{enumi})}
@@ -492,8 +490,7 @@ B. Williams
492
490
493\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
491\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
494
492
495−\section{\texorpdfstring{Definition
496−Lists}{Definition Lists}}\label{definition-lists}
493+\section{Definition Lists}\label{definition-lists}
497
494
498Tight using spaces:
495Tight using spaces:
499
496
@@ -596,7 +593,7 @@ orange fruit
596\end{enumerate}
593\end{enumerate}
597\end{description}
594\end{description}
598
595
599−\section{\texorpdfstring{HTML Blocks}{HTML Blocks}}\label{html-blocks}
596+\section{HTML Blocks}\label{html-blocks}
600
597
601Simple block on one line:
598Simple block on one line:
602
599
@@ -658,7 +655,7 @@ Hr's:
658
655
659\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
656\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
660
657
661−\section{\texorpdfstring{Inline Markup}{Inline Markup}}\label{inline-markup}
658+\section{Inline Markup}\label{inline-markup}
662
659
663This is \emph{emphasized}, and so \emph{is this}.
660This is \emph{emphasized}, and so \emph{is this}.
664
661
@@ -690,8 +687,7 @@ spaces: a\^{}b c\^{}d, a\textasciitilde{}b c\textasciitilde{}d.
690
687
691\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
688\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
692
689
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}
695
691
696``Hello,'' said the spider. ``\,`Shelob' is my name.''
692``Hello,'' said the spider. ``\,`Shelob' is my name.''
697
693
@@ -712,7 +708,7 @@ Ellipses\ldots{}and\ldots{}and\ldots{}.
712
708
713\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
709\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
714
710
715−\section{\texorpdfstring{LaTeX}{LaTeX}}\label{latex}
711+\section{LaTeX}\label{latex}
716
712
717\begin{itemize}
713\begin{itemize}
718\itemsep1pt\parskip0pt\parsep0pt
714\itemsep1pt\parskip0pt\parsep0pt
@@ -760,8 +756,7 @@ Cat & 1 \\ \hline
760
756
761\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
757\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
762
758
763−\section{\texorpdfstring{Special
764−Characters}{Special Characters}}\label{special-characters}
759+\section{Special Characters}\label{special-characters}
765
760
766Here is some unicode:
761Here is some unicode:
767
762
@@ -823,9 +818,9 @@ Minus: -
823
818
824\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
819\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
825
820
826−\section{\texorpdfstring{Links}{Links}}\label{links}
821+\section{Links}\label{links}
827
822
828−\subsection{\texorpdfstring{Explicit}{Explicit}}\label{explicit}
823+\subsection{Explicit}\label{explicit}
829
824
830Just a \href{/url/}{URL}.
825Just a \href{/url/}{URL}.
831
826
@@ -845,7 +840,7 @@ Just a \href{/url/}{URL}.
845
840
846\href{}{Empty}.
841\href{}{Empty}.
847
842
848−\subsection{\texorpdfstring{Reference}{Reference}}\label{reference}
843+\subsection{Reference}\label{reference}
849
844
850Foo \href{/url/}{bar}.
845Foo \href{/url/}{bar}.
851
846
@@ -873,8 +868,7 @@ Foo \href{/url/}{bar}.
873
868
874Foo \href{/url/}{biz}.
869Foo \href{/url/}{biz}.
875
870
876−\subsection{\texorpdfstring{With
877−ampersands}{With ampersands}}\label{with-ampersands}
871+\subsection{With ampersands}\label{with-ampersands}
878
872
879Here's a \href{http://example.com/?foo=1\&bar=2}{link with an ampersand in the
873Here's a \href{http://example.com/?foo=1\&bar=2}{link with an ampersand in the
880URL}.
874URL}.
@@ -886,7 +880,7 @@ Here's an \href{/script?foo=1\&bar=2}{inline link}.
886
880
887Here's an \href{/script?foo=1\&bar=2}{inline link in pointy braces}.
881Here's an \href{/script?foo=1\&bar=2}{inline link in pointy braces}.
888
882
889−\subsection{\texorpdfstring{Autolinks}{Autolinks}}\label{autolinks}
883+\subsection{Autolinks}\label{autolinks}
890
884
891With an ampersand: \url{http://example.com/?foo=1\&bar=2}
885With an ampersand: \url{http://example.com/?foo=1\&bar=2}
892
886
@@ -916,7 +910,7 @@ or here: <http://example.com/>
916
910
917\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
911\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
918
912
919−\section{\texorpdfstring{Images}{Images}}\label{images}
913+\section{Images}\label{images}
920
914
921From ``Voyage dans la Lune'' by Georges Melies (1902):
915From ``Voyage dans la Lune'' by Georges Melies (1902):
922
916
@@ -930,7 +924,7 @@ Here is a movie \includegraphics{movie.jpg} icon.
930
924
931\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
925\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
932
926
933−\section{\texorpdfstring{Footnotes}{Footnotes}}\label{footnotes}
927+\section{Footnotes}\label{footnotes}
934
928
935Here is a footnote reference,\footnote{Here is the footnote. It can go
929Here is a footnote reference,\footnote{Here is the footnote. It can go
936 anywhere after the footnote reference. It need not be placed at the end of
930 anywhere after the footnote reference. It need not be placed at the end of