Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit 747dfc7

Browse files
committed
Avoid multi-line emph in LaTeX backend
`markupWarning` often processes inputs which span across paragraphs. Unfortunately, LaTeX's `emph` is not made to handle this (and will crash). Fixes #936.
1 parent abb448f commit 747dfc7

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

haddock-api/src/Haddock/Backends/LaTeX.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ parLatexMarkup ppId = Markup {
11911191
markupIdentifier = markupId ppId,
11921192
markupIdentifierUnchecked = markupId (ppVerbOccName . fmap snd),
11931193
markupModule = \m _ -> let (mdl,_ref) = break (=='#') m in tt (text mdl),
1194-
markupWarning = \p v -> emph (p v),
1194+
markupWarning = \p v -> p v,
11951195
markupEmphasis = \p v -> emph (p v),
11961196
markupBold = \p v -> bold (p v),
11971197
markupMonospaced = \p _ -> tt (p Mono),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
\haddockmoduleheading{Deprecated}
2+
\label{module:Deprecated}
3+
\haddockbeginheader
4+
{\haddockverb\begin{verbatim}
5+
module Deprecated (
6+
deprecated
7+
) where\end{verbatim}}
8+
\haddockendheader
9+
10+
\begin{haddockdesc}
11+
\item[\begin{tabular}{@{}l}
12+
deprecated\ ::\ Int
13+
\end{tabular}]\haddockbegindoc
14+
Deprecated: Don't use this\par
15+
Docs for something deprecated\par
16+
17+
\end{haddockdesc}

latex-test/ref/Deprecated/haddock.sty

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
% Default Haddock style definitions. To use your own style, invoke
2+
% Haddock with the option --latex-style=mystyle.
3+
4+
\usepackage{tabulary} % see below
5+
6+
% make hyperlinks in the PDF, and add an expandabale index
7+
\usepackage[pdftex,bookmarks=true]{hyperref}
8+
9+
\newenvironment{haddocktitle}
10+
{\begin{center}\bgroup\large\bfseries}
11+
{\egroup\end{center}}
12+
\newenvironment{haddockprologue}{\vspace{1in}}{}
13+
14+
\newcommand{\haddockmoduleheading}[1]{\chapter{\texttt{#1}}}
15+
16+
\newcommand{\haddockbeginheader}{\hrulefill}
17+
\newcommand{\haddockendheader}{\noindent\hrulefill}
18+
19+
% a little gap before the ``Methods'' header
20+
\newcommand{\haddockpremethods}{\vspace{2ex}}
21+
22+
% inserted before \\begin{verbatim}
23+
\newcommand{\haddockverb}{\small}
24+
25+
% an identifier: add an index entry
26+
\newcommand{\haddockid}[1]{\haddocktt{#1}\index{#1@\texttt{#1}}}
27+
28+
% The tabulary environment lets us have a column that takes up ``the
29+
% rest of the space''. Unfortunately it doesn't allow
30+
% the \end{tabulary} to be in the expansion of a macro, it must appear
31+
% literally in the document text, so Haddock inserts
32+
% the \end{tabulary} itself.
33+
\newcommand{\haddockbeginconstrs}{\begin{tabulary}{\linewidth}{@{}llJ@{}}}
34+
\newcommand{\haddockbeginargs}{\begin{tabulary}{\linewidth}{@{}llJ@{}}}
35+
36+
\newcommand{\haddocktt}[1]{{\small \texttt{#1}}}
37+
\newcommand{\haddockdecltt}[1]{{\small\bfseries \texttt{#1}}}
38+
39+
\makeatletter
40+
\newenvironment{haddockdesc}
41+
{\list{}{\labelwidth\z@ \itemindent-\leftmargin
42+
\let\makelabel\haddocklabel}}
43+
{\endlist}
44+
\newcommand*\haddocklabel[1]{\hspace\labelsep\haddockdecltt{#1}}
45+
\makeatother
46+
47+
% after a declaration, start a new line for the documentation.
48+
% Otherwise, the documentation starts right after the declaration,
49+
% because we're using the list environment and the declaration is the
50+
% ``label''. I tried making this newline part of the label, but
51+
% couldn't get that to work reliably (the space seemed to stretch
52+
% sometimes).
53+
\newcommand{\haddockbegindoc}{\hfill\\[1ex]}
54+
55+
% spacing between paragraphs and no \parindent looks better
56+
\parskip=10pt plus2pt minus2pt
57+
\setlength{\parindent}{0cm}

latex-test/ref/Deprecated/main.tex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
\documentclass{book}
2+
\usepackage{haddock}
3+
\begin{document}
4+
\begin{titlepage}
5+
\begin{haddocktitle}
6+
7+
\end{haddocktitle}
8+
\end{titlepage}
9+
\tableofcontents
10+
\input{Deprecated}
11+
\end{document}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Deprecated where
2+
3+
-- | Docs for something deprecated
4+
deprecated :: Int
5+
deprecated = 1
6+
7+
{-# DEPRECATED deprecated "Don't use this" #-}

0 commit comments

Comments
 (0)