git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Always create labels for sections.
8d19e45John MacFarlane
src/Text/Pandoc/Writers/LaTeX.hs+9−7
@@ -507,14 +507,16 @@ sectionHeader unnumbered ref level lst = do
507 opts <- gets stOptions
507 opts <- gets stOptions
508 let level' = if book || writerChapters opts then level - 1 else level
508 let level' = if book || writerChapters opts then level - 1 else level
509 internalLinks <- gets stInternalLinks
509 internalLinks <- gets stInternalLinks
510− let refLabel lab = (if ref `elem` internalLinks
510+ let refLabel x = (if ref `elem` internalLinks
511− then text "\\hyperdef"
511+ then text "\\hyperdef"
512 <> braces empty
512 <> braces empty
513 <> braces (text ref)
513 <> braces (text ref)
514− <> braces (lab <> text "\\label"
514+ <> braces x
515− <> braces (text ref))
516− else lab)
515+ else x)
517− let headerWith x y = refLabel $ text x <> y
516+ let headerWith x y r = refLabel $ text x <> y <>
517+ if null r
518+ then empty
519+ else text "\\label" <> braces (text r)
518 let sectionType = case level' of
520 let sectionType = case level' of
519 0 | writerBeamer opts -> "part"
521 0 | writerBeamer opts -> "part"
520 | otherwise -> "chapter"
522 | otherwise -> "chapter"
@@ -526,7 +528,7 @@ sectionHeader unnumbered ref level lst = do
526 _ -> ""
528 _ -> ""
527 return $ if level' > 5
529 return $ if level' > 5
528 then txt
530 then txt
529− else headerWith ('\\':sectionType) stuffing
531+ else headerWith ('\\':sectionType) stuffing ref
530 $$ if unnumbered
532 $$ if unnumbered
531 then "\\addcontentsline{toc}" <>
533 then "\\addcontentsline{toc}" <>
532 braces (text sectionType) <>
534 braces (text sectionType) <>
tests/writer.latex+32−31
@@ -77,31 +77,32 @@ markdown test suite.
77
77
78\begin{center}\rule{3in}{0.4pt}\end{center}
78\begin{center}\rule{3in}{0.4pt}\end{center}
79
79
80−\section{Headers}
80+\section{Headers}\label{headers}
81
81
82−\subsection{Level 2 with an \href{/url}{embedded link}}
82+\subsection{Level 2 with an \href{/url}{embedded
83+link}}\label{level-2-with-an-embedded-link}
83
84
84−\subsubsection{Level 3 with \emph{emphasis}}
85+\subsubsection{Level 3 with \emph{emphasis}}\label{level-3-with-emphasis}
85
86
86−\paragraph{Level 4}
87+\paragraph{Level 4}\label{level-4}
87
88
88−\subparagraph{Level 5}
89+\subparagraph{Level 5}\label{level-5}
89
90
90−\section{Level 1}
91+\section{Level 1}\label{level-1}
91
92
92−\subsection{Level 2 with \emph{emphasis}}
93+\subsection{Level 2 with \emph{emphasis}}\label{level-2-with-emphasis}
93
94
94−\subsubsection{Level 3}
95+\subsubsection{Level 3}\label{level-3}
95
96
96with no blank line
97with no blank line
97
98
98−\subsection{Level 2}
99+\subsection{Level 2}\label{level-2}
99
100
100with no blank line
101with no blank line
101
102
102\begin{center}\rule{3in}{0.4pt}\end{center}
103\begin{center}\rule{3in}{0.4pt}\end{center}
103
104
104−\section{Paragraphs}
105+\section{Paragraphs}\label{paragraphs}
105
106
106Here's a regular paragraph.
107Here's a regular paragraph.
107
108
@@ -115,7 +116,7 @@ There should be a hard line break\\here.
115
116
116\begin{center}\rule{3in}{0.4pt}\end{center}
117\begin{center}\rule{3in}{0.4pt}\end{center}
117
118
118−\section{Block Quotes}
119+\section{Block Quotes}\label{block-quotes}
119
120
120E-mail style:
121E-mail style:
121
122
@@ -160,7 +161,7 @@ And a following paragraph.
160
161
161\begin{center}\rule{3in}{0.4pt}\end{center}
162\begin{center}\rule{3in}{0.4pt}\end{center}
162
163
163−\section{Code Blocks}
164+\section{Code Blocks}\label{code-blocks}
164
165
165Code:
166Code:
166
167
@@ -184,9 +185,9 @@ These should not be escaped: \$ \\ \> \[ \{
184
185
185\begin{center}\rule{3in}{0.4pt}\end{center}
186\begin{center}\rule{3in}{0.4pt}\end{center}
186
187
187−\section{Lists}
188+\section{Lists}\label{lists}
188
189
189−\subsection{Unordered}
190+\subsection{Unordered}\label{unordered}
190
191
191Asterisks tight:
192Asterisks tight:
192
193
@@ -257,7 +258,7 @@ Minuses loose:
257 Minus 3
258 Minus 3
258\end{itemize}
259\end{itemize}
259
260
260−\subsection{Ordered}
261+\subsection{Ordered}\label{ordered}
261
262
262Tight:
263Tight:
263
264
@@ -323,7 +324,7 @@ Multiple paragraphs:
323 Item 3.
324 Item 3.
324\end{enumerate}
325\end{enumerate}
325
326
326−\subsection{Nested}
327+\subsection{Nested}\label{nested}
327
328
328\begin{itemize}
329\begin{itemize}
329\itemsep1pt\parskip0pt\parsep0pt
330\itemsep1pt\parskip0pt\parsep0pt
@@ -388,7 +389,7 @@ Same thing but with paragraphs:
388 Third
389 Third
389\end{enumerate}
390\end{enumerate}
390
391
391−\subsection{Tabs and spaces}
392+\subsection{Tabs and spaces}\label{tabs-and-spaces}
392
393
393\begin{itemize}
394\begin{itemize}
394\item
395\item
@@ -404,7 +405,7 @@ Same thing but with paragraphs:
404 \end{itemize}
405 \end{itemize}
405\end{itemize}
406\end{itemize}
406
407
407−\subsection{Fancy list markers}
408+\subsection{Fancy list markers}\label{fancy-list-markers}
408
409
409\begin{enumerate}
410\begin{enumerate}
410\def\labelenumi{(\arabic{enumi})}
411\def\labelenumi{(\arabic{enumi})}
@@ -492,7 +493,7 @@ B. Williams
492
493
493\begin{center}\rule{3in}{0.4pt}\end{center}
494\begin{center}\rule{3in}{0.4pt}\end{center}
494
495
495−\section{Definition Lists}
496+\section{Definition Lists}\label{definition-lists}
496
497
497Tight using spaces:
498Tight using spaces:
498
499
@@ -595,7 +596,7 @@ orange fruit
595\end{enumerate}
596\end{enumerate}
596\end{description}
597\end{description}
597
598
598−\section{HTML Blocks}
599+\section{HTML Blocks}\label{html-blocks}
599
600
600Simple block on one line:
601Simple block on one line:
601
602
@@ -657,7 +658,7 @@ Hr's:
657
658
658\begin{center}\rule{3in}{0.4pt}\end{center}
659\begin{center}\rule{3in}{0.4pt}\end{center}
659
660
660−\section{Inline Markup}
661+\section{Inline Markup}\label{inline-markup}
661
662
662This is \emph{emphasized}, and so \emph{is this}.
663This is \emph{emphasized}, and so \emph{is this}.
663
664
@@ -689,7 +690,7 @@ spaces: a\^{}b c\^{}d, a\textasciitilde{}b c\textasciitilde{}d.
689
690
690\begin{center}\rule{3in}{0.4pt}\end{center}
691\begin{center}\rule{3in}{0.4pt}\end{center}
691
692
692−\section{Smart quotes, ellipses, dashes}
693+\section{Smart quotes, ellipses, dashes}\label{smart-quotes-ellipses-dashes}
693
694
694``Hello,'' said the spider. ``\,`Shelob' is my name.''
695``Hello,'' said the spider. ``\,`Shelob' is my name.''
695
696
@@ -710,7 +711,7 @@ Ellipses\ldots{}and\ldots{}and\ldots{}.
710
711
711\begin{center}\rule{3in}{0.4pt}\end{center}
712\begin{center}\rule{3in}{0.4pt}\end{center}
712
713
713−\section{LaTeX}
714+\section{LaTeX}\label{latex}
714
715
715\begin{itemize}
716\begin{itemize}
716\itemsep1pt\parskip0pt\parsep0pt
717\itemsep1pt\parskip0pt\parsep0pt
@@ -758,7 +759,7 @@ Cat & 1 \\ \hline
758
759
759\begin{center}\rule{3in}{0.4pt}\end{center}
760\begin{center}\rule{3in}{0.4pt}\end{center}
760
761
761−\section{Special Characters}
762+\section{Special Characters}\label{special-characters}
762
763
763Here is some unicode:
764Here is some unicode:
764
765
@@ -820,9 +821,9 @@ Minus: -
820
821
821\begin{center}\rule{3in}{0.4pt}\end{center}
822\begin{center}\rule{3in}{0.4pt}\end{center}
822
823
823−\section{Links}
824+\section{Links}\label{links}
824
825
825−\subsection{Explicit}
826+\subsection{Explicit}\label{explicit}
826
827
827Just a \href{/url/}{URL}.
828Just a \href{/url/}{URL}.
828
829
@@ -842,7 +843,7 @@ Just a \href{/url/}{URL}.
842
843
843\href{}{Empty}.
844\href{}{Empty}.
844
845
845−\subsection{Reference}
846+\subsection{Reference}\label{reference}
846
847
847Foo \href{/url/}{bar}.
848Foo \href{/url/}{bar}.
848
849
@@ -870,7 +871,7 @@ Foo \href{/url/}{bar}.
870
871
871Foo \href{/url/}{biz}.
872Foo \href{/url/}{biz}.
872
873
873−\subsection{With ampersands}
874+\subsection{With ampersands}\label{with-ampersands}
874
875
875Here's a \href{http://example.com/?foo=1\&bar=2}{link with an ampersand in the
876Here's a \href{http://example.com/?foo=1\&bar=2}{link with an ampersand in the
876URL}.
877URL}.
@@ -882,7 +883,7 @@ Here's an \href{/script?foo=1\&bar=2}{inline link}.
882
883
883Here's an \href{/script?foo=1\&bar=2}{inline link in pointy braces}.
884Here's an \href{/script?foo=1\&bar=2}{inline link in pointy braces}.
884
885
885−\subsection{Autolinks}
886+\subsection{Autolinks}\label{autolinks}
886
887
887With an ampersand: \url{http://example.com/?foo=1\&bar=2}
888With an ampersand: \url{http://example.com/?foo=1\&bar=2}
888
889
@@ -911,7 +912,7 @@ or here: <http://example.com/>
911
912
912\begin{center}\rule{3in}{0.4pt}\end{center}
913\begin{center}\rule{3in}{0.4pt}\end{center}
913
914
914−\section{Images}
915+\section{Images}\label{images}
915
916
916From ``Voyage dans la Lune'' by Georges Melies (1902):
917From ``Voyage dans la Lune'' by Georges Melies (1902):
917
918
@@ -925,7 +926,7 @@ Here is a movie \includegraphics{movie.jpg} icon.
925
926
926\begin{center}\rule{3in}{0.4pt}\end{center}
927\begin{center}\rule{3in}{0.4pt}\end{center}
927
928
928−\section{Footnotes}
929+\section{Footnotes}\label{footnotes}
929
930
930Here is a footnote reference,\footnote{Here is the footnote. It can go
931Here is a footnote reference,\footnote{Here is the footnote. It can go
931 anywhere after the footnote reference. It need not be placed at the end of
932 anywhere after the footnote reference. It need not be placed at the end of