diff options
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 16 | ||||
| -rw-r--r-- | tests/writer.latex | 63 | 
2 files changed, 41 insertions, 38 deletions
| diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 287a978f4..04bb3f9e2 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -507,14 +507,16 @@ sectionHeader unnumbered ref level lst = do    opts <- gets stOptions    let level' = if book || writerChapters opts then level - 1 else level    internalLinks <- gets stInternalLinks -  let refLabel lab = (if ref `elem` internalLinks -                         then text "\\hyperdef" +  let refLabel x = (if ref `elem` internalLinks +                       then text "\\hyperdef"                                  <> braces empty                                  <> braces (text ref) -                                <> braces (lab <> text "\\label" -                                               <> braces (text ref)) -                         else lab) -  let headerWith x y = refLabel $ text x <> y +                                <> braces x +                       else x) +  let headerWith x y r = refLabel $ text x <> y <> +                             if null r +                                then empty +                                else text "\\label" <> braces (text r)    let sectionType = case level' of                            0  | writerBeamer opts -> "part"                               | otherwise -> "chapter" @@ -526,7 +528,7 @@ sectionHeader unnumbered ref level lst = do                            _  -> ""    return $ if level' > 5                then txt -              else headerWith ('\\':sectionType) stuffing +              else headerWith ('\\':sectionType) stuffing ref                     $$ if unnumbered                           then "\\addcontentsline{toc}" <>                                  braces (text sectionType) <> diff --git a/tests/writer.latex b/tests/writer.latex index 04924f0b1..0e7c81ceb 100644 --- a/tests/writer.latex +++ b/tests/writer.latex @@ -77,31 +77,32 @@ markdown test suite.  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Headers} +\section{Headers}\label{headers} -\subsection{Level 2 with an \href{/url}{embedded link}} +\subsection{Level 2 with an \href{/url}{embedded +link}}\label{level-2-with-an-embedded-link} -\subsubsection{Level 3 with \emph{emphasis}} +\subsubsection{Level 3 with \emph{emphasis}}\label{level-3-with-emphasis} -\paragraph{Level 4} +\paragraph{Level 4}\label{level-4} -\subparagraph{Level 5} +\subparagraph{Level 5}\label{level-5} -\section{Level 1} +\section{Level 1}\label{level-1} -\subsection{Level 2 with \emph{emphasis}} +\subsection{Level 2 with \emph{emphasis}}\label{level-2-with-emphasis} -\subsubsection{Level 3} +\subsubsection{Level 3}\label{level-3}  with no blank line -\subsection{Level 2} +\subsection{Level 2}\label{level-2}  with no blank line  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Paragraphs} +\section{Paragraphs}\label{paragraphs}  Here's a regular paragraph. @@ -115,7 +116,7 @@ There should be a hard line break\\here.  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Block Quotes} +\section{Block Quotes}\label{block-quotes}  E-mail style: @@ -160,7 +161,7 @@ And a following paragraph.  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Code Blocks} +\section{Code Blocks}\label{code-blocks}  Code: @@ -184,9 +185,9 @@ These should not be escaped:  \$ \\ \> \[ \{  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Lists} +\section{Lists}\label{lists} -\subsection{Unordered} +\subsection{Unordered}\label{unordered}  Asterisks tight: @@ -257,7 +258,7 @@ Minuses loose:    Minus 3  \end{itemize} -\subsection{Ordered} +\subsection{Ordered}\label{ordered}  Tight: @@ -323,7 +324,7 @@ Multiple paragraphs:    Item 3.  \end{enumerate} -\subsection{Nested} +\subsection{Nested}\label{nested}  \begin{itemize}  \itemsep1pt\parskip0pt\parsep0pt @@ -388,7 +389,7 @@ Same thing but with paragraphs:    Third  \end{enumerate} -\subsection{Tabs and spaces} +\subsection{Tabs and spaces}\label{tabs-and-spaces}  \begin{itemize}  \item @@ -404,7 +405,7 @@ Same thing but with paragraphs:    \end{itemize}  \end{itemize} -\subsection{Fancy list markers} +\subsection{Fancy list markers}\label{fancy-list-markers}  \begin{enumerate}  \def\labelenumi{(\arabic{enumi})} @@ -492,7 +493,7 @@ B. Williams  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Definition Lists} +\section{Definition Lists}\label{definition-lists}  Tight using spaces: @@ -595,7 +596,7 @@ orange fruit  \end{enumerate}  \end{description} -\section{HTML Blocks} +\section{HTML Blocks}\label{html-blocks}  Simple block on one line: @@ -657,7 +658,7 @@ Hr's:  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Inline Markup} +\section{Inline Markup}\label{inline-markup}  This is \emph{emphasized}, and so \emph{is this}. @@ -689,7 +690,7 @@ spaces: a\^{}b c\^{}d, a\textasciitilde{}b c\textasciitilde{}d.  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Smart quotes, ellipses, dashes} +\section{Smart quotes, ellipses, dashes}\label{smart-quotes-ellipses-dashes}  ``Hello,'' said the spider. ``\,`Shelob' is my name.'' @@ -710,7 +711,7 @@ Ellipses\ldots{}and\ldots{}and\ldots{}.  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{LaTeX} +\section{LaTeX}\label{latex}  \begin{itemize}  \itemsep1pt\parskip0pt\parsep0pt @@ -758,7 +759,7 @@ Cat    & 1      \\ \hline  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Special Characters} +\section{Special Characters}\label{special-characters}  Here is some unicode: @@ -820,9 +821,9 @@ Minus: -  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Links} +\section{Links}\label{links} -\subsection{Explicit} +\subsection{Explicit}\label{explicit}  Just a \href{/url/}{URL}. @@ -842,7 +843,7 @@ Just a \href{/url/}{URL}.  \href{}{Empty}. -\subsection{Reference} +\subsection{Reference}\label{reference}  Foo \href{/url/}{bar}. @@ -870,7 +871,7 @@ Foo \href{/url/}{bar}.  Foo \href{/url/}{biz}. -\subsection{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}. @@ -882,7 +883,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{Autolinks} +\subsection{Autolinks}\label{autolinks}  With an ampersand: \url{http://example.com/?foo=1\&bar=2} @@ -911,7 +912,7 @@ or here: <http://example.com/>  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{Images} +\section{Images}\label{images}  From ``Voyage dans la Lune'' by Georges Melies (1902): @@ -925,7 +926,7 @@ Here is a movie \includegraphics{movie.jpg} icon.  \begin{center}\rule{3in}{0.4pt}\end{center} -\section{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 | 
