diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-12-15 10:03:19 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-12-15 10:06:03 -0800 |
commit | 47c360e0795a5f27e4906ea22fff388b779f270a (patch) | |
tree | 18808b42697ea719cbc511c76dcca04bca7d5aff | |
parent | 544f3e5b45c7452c7bb90a630ec0904c4808113e (diff) |
Improved texorpdfstring patch #1148.
* Make LaTeX reader recognize texorpdfstring.
* Don't use texorpdfstring unless it's actually needed.
* Fix tests.
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 1 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 9 | ||||
-rw-r--r-- | tests/Tests/Writers/LaTeX.hs | 2 | ||||
-rw-r--r-- | tests/lhs-test.latex | 2 | ||||
-rw-r--r-- | tests/lhs-test.latex+lhs | 2 | ||||
-rw-r--r-- | tests/writer.latex | 62 |
6 files changed, 38 insertions, 40 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 9420d602f..e1976035d 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -417,6 +417,7 @@ inlineCommands = M.fromList $ , ("(", mathInline $ manyTill anyChar (try $ string "\\)")) , ("[", mathDisplay $ manyTill anyChar (try $ string "\\]")) , ("ensuremath", mathInline $ braced) + , ("texorpdfstring", (\_ x -> x) <$> tok <*> tok) , ("P", lit "¶") , ("S", lit "§") , ("$", lit "$") diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index ee9f7f620..2c86d1a6e 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -626,9 +626,12 @@ sectionHeader unnumbered ref level lst = do then return empty else do return $ brackets txtNoNotes - let stuffing = star <> optional <> braces (text "\\texorpdfstring" - <> braces txt - <> braces (text plain)) + let contents = if render Nothing txt == plain + then braces txt + else braces (text "\\texorpdfstring" + <> braces txt + <> braces (text plain)) + let stuffing = star <> optional <> contents book <- gets stBook opts <- gets stOptions let level' = if book || writerChapters opts then level - 1 else level diff --git a/tests/Tests/Writers/LaTeX.hs b/tests/Tests/Writers/LaTeX.hs index 6d46a15d2..f083176d0 100644 --- a/tests/Tests/Writers/LaTeX.hs +++ b/tests/Tests/Writers/LaTeX.hs @@ -62,7 +62,7 @@ tests = [ testGroup "code blocks" "\\begin{description}\n\\item[foo] ~ \n\\subsection{bar}\n\nbaz\n\\end{description}" , "containing image" =: header 1 (image "imgs/foo.jpg" "" (text "Alt text")) =?> - "\\section{\\protect\\includegraphics{imgs/foo.jpg}}" + "\\section{\\texorpdfstring{\\protect\\includegraphics{imgs/foo.jpg}}{Alt text}}" ] , testGroup "inline code" [ "struck out and highlighted" =: diff --git a/tests/lhs-test.latex b/tests/lhs-test.latex index d8f60e545..6f2fdfb77 100644 --- a/tests/lhs-test.latex +++ b/tests/lhs-test.latex @@ -70,7 +70,7 @@ \begin{document} -\section{\texorpdfstring{lhs test}{lhs test}}\label{lhs-test} +\section{lhs test}\label{lhs-test} \texttt{unsplit} is an arrow that takes a pair of values and combines them to return a single value: diff --git a/tests/lhs-test.latex+lhs b/tests/lhs-test.latex+lhs index 8e1ac55b5..77f0e08ff 100644 --- a/tests/lhs-test.latex+lhs +++ b/tests/lhs-test.latex+lhs @@ -51,7 +51,7 @@ \begin{document} -\section{\texorpdfstring{lhs test}{lhs test}}\label{lhs-test} +\section{lhs test}\label{lhs-test} \texttt{unsplit} is an arrow that takes a pair of values and combines them to return a single value: diff --git a/tests/writer.latex b/tests/writer.latex index ee886e757..5b41bac75 100644 --- a/tests/writer.latex +++ b/tests/writer.latex @@ -72,7 +72,7 @@ markdown test suite. \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Headers}{Headers}}\label{headers} +\section{Headers}\label{headers} \subsection{\texorpdfstring{Level 2 with an \href{/url}{embedded link}}{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} \subsubsection{\texorpdfstring{Level 3 with \emph{emphasis}}{Level 3 with emphasis}}\label{level-3-with-emphasis} -\paragraph{\texorpdfstring{Level 4}{Level 4}}\label{level-4} +\paragraph{Level 4}\label{level-4} -\subparagraph{\texorpdfstring{Level 5}{Level 5}}\label{level-5} +\subparagraph{Level 5}\label{level-5} -\section{\texorpdfstring{Level 1}{Level 1}}\label{level-1} +\section{Level 1}\label{level-1} \subsection{\texorpdfstring{Level 2 with \emph{emphasis}}{Level 2 with emphasis}}\label{level-2-with-emphasis} -\subsubsection{\texorpdfstring{Level 3}{Level 3}}\label{level-3} +\subsubsection{Level 3}\label{level-3} with no blank line -\subsection{\texorpdfstring{Level 2}{Level 2}}\label{level-2} +\subsection{Level 2}\label{level-2} with no blank line \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Paragraphs}{Paragraphs}}\label{paragraphs} +\section{Paragraphs}\label{paragraphs} Here's a regular paragraph. @@ -113,7 +113,7 @@ There should be a hard line break\\here. \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Block Quotes}{Block Quotes}}\label{block-quotes} +\section{Block Quotes}\label{block-quotes} E-mail style: @@ -158,7 +158,7 @@ And a following paragraph. \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Code Blocks}{Code Blocks}}\label{code-blocks} +\section{Code Blocks}\label{code-blocks} Code: @@ -182,9 +182,9 @@ These should not be escaped: \$ \\ \> \[ \{ \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Lists}{Lists}}\label{lists} +\section{Lists}\label{lists} -\subsection{\texorpdfstring{Unordered}{Unordered}}\label{unordered} +\subsection{Unordered}\label{unordered} Asterisks tight: @@ -255,7 +255,7 @@ Minuses loose: Minus 3 \end{itemize} -\subsection{\texorpdfstring{Ordered}{Ordered}}\label{ordered} +\subsection{Ordered}\label{ordered} Tight: @@ -321,7 +321,7 @@ Multiple paragraphs: Item 3. \end{enumerate} -\subsection{\texorpdfstring{Nested}{Nested}}\label{nested} +\subsection{Nested}\label{nested} \begin{itemize} \itemsep1pt\parskip0pt\parsep0pt @@ -386,8 +386,7 @@ Same thing but with paragraphs: Third \end{enumerate} -\subsection{\texorpdfstring{Tabs and -spaces}{Tabs and spaces}}\label{tabs-and-spaces} +\subsection{Tabs and spaces}\label{tabs-and-spaces} \begin{itemize} \item @@ -403,8 +402,7 @@ spaces}{Tabs and spaces}}\label{tabs-and-spaces} \end{itemize} \end{itemize} -\subsection{\texorpdfstring{Fancy list -markers}{Fancy list markers}}\label{fancy-list-markers} +\subsection{Fancy list markers}\label{fancy-list-markers} \begin{enumerate} \def\labelenumi{(\arabic{enumi})} @@ -492,8 +490,7 @@ B. Williams \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Definition -Lists}{Definition Lists}}\label{definition-lists} +\section{Definition Lists}\label{definition-lists} Tight using spaces: @@ -596,7 +593,7 @@ orange fruit \end{enumerate} \end{description} -\section{\texorpdfstring{HTML Blocks}{HTML Blocks}}\label{html-blocks} +\section{HTML Blocks}\label{html-blocks} Simple block on one line: @@ -658,7 +655,7 @@ Hr's: \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Inline Markup}{Inline Markup}}\label{inline-markup} +\section{Inline Markup}\label{inline-markup} This is \emph{emphasized}, and so \emph{is this}. @@ -690,8 +687,7 @@ spaces: a\^{}b c\^{}d, a\textasciitilde{}b c\textasciitilde{}d. \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Smart quotes, ellipses, -dashes}{Smart quotes, ellipses, dashes}}\label{smart-quotes-ellipses-dashes} +\section{Smart quotes, ellipses, dashes}\label{smart-quotes-ellipses-dashes} ``Hello,'' said the spider. ``\,`Shelob' is my name.'' @@ -712,7 +708,7 @@ Ellipses\ldots{}and\ldots{}and\ldots{}. \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{LaTeX}{LaTeX}}\label{latex} +\section{LaTeX}\label{latex} \begin{itemize} \itemsep1pt\parskip0pt\parsep0pt @@ -760,8 +756,7 @@ Cat & 1 \\ \hline \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Special -Characters}{Special Characters}}\label{special-characters} +\section{Special Characters}\label{special-characters} Here is some unicode: @@ -823,9 +818,9 @@ Minus: - \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Links}{Links}}\label{links} +\section{Links}\label{links} -\subsection{\texorpdfstring{Explicit}{Explicit}}\label{explicit} +\subsection{Explicit}\label{explicit} Just a \href{/url/}{URL}. @@ -845,7 +840,7 @@ Just a \href{/url/}{URL}. \href{}{Empty}. -\subsection{\texorpdfstring{Reference}{Reference}}\label{reference} +\subsection{Reference}\label{reference} Foo \href{/url/}{bar}. @@ -873,8 +868,7 @@ Foo \href{/url/}{bar}. Foo \href{/url/}{biz}. -\subsection{\texorpdfstring{With -ampersands}{With ampersands}}\label{with-ampersands} +\subsection{With ampersands}\label{with-ampersands} Here's a \href{http://example.com/?foo=1\&bar=2}{link with an ampersand in the URL}. @@ -886,7 +880,7 @@ Here's an \href{/script?foo=1\&bar=2}{inline link}. Here's an \href{/script?foo=1\&bar=2}{inline link in pointy braces}. -\subsection{\texorpdfstring{Autolinks}{Autolinks}}\label{autolinks} +\subsection{Autolinks}\label{autolinks} With an ampersand: \url{http://example.com/?foo=1\&bar=2} @@ -916,7 +910,7 @@ or here: <http://example.com/> \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Images}{Images}}\label{images} +\section{Images}\label{images} From ``Voyage dans la Lune'' by Georges Melies (1902): @@ -930,7 +924,7 @@ Here is a movie \includegraphics{movie.jpg} icon. \begin{center}\rule{0.5\linewidth}{\linethickness}\end{center} -\section{\texorpdfstring{Footnotes}{Footnotes}}\label{footnotes} +\section{Footnotes}\label{footnotes} Here is a footnote reference,\footnote{Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of |