New option "font-encoding".
[docutils.git] / test / test_writers / test_latex2e.py
blob948a77b0b8aac9e18d6ff89fa805afce8d895e45
1 #! /usr/bin/env python
3 # Author: engelbert gruber
4 # Contact: grubert@users.sourceforge.net
5 # Revision: $Revision$
6 # Date: $Date$
7 # Copyright: This module has been placed in the public domain.
9 """
10 Tests for latex2e writer.
11 """
13 from __init__ import DocutilsTestSupport
15 def suite():
16 s = DocutilsTestSupport.PublishTestSuite('latex')
17 s.generateTests(totest)
18 return s
21 latex_head = """\
22 \\documentclass[10pt,a4paper,english]{article}
23 \\usepackage{babel}
24 \\usepackage{ae}
25 \\usepackage{shortvrb}
26 \\usepackage[latin1]{inputenc}
27 \\usepackage{tabularx}
28 \\usepackage{longtable}
29 \\setlength{\\extrarowheight}{2pt}
30 \\usepackage{amsmath}
31 \\usepackage{graphicx}
32 \\usepackage{color}
33 \\usepackage{multirow}
34 \\usepackage{ifthen}
35 \\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
36 \\usepackage[DIV12]{typearea}
37 %% generator Docutils: http://docutils.sourceforge.net/
38 \\newlength{\\admonitionwidth}
39 \\setlength{\\admonitionwidth}{0.9\\textwidth}
40 \\newlength{\\docinfowidth}
41 \\setlength{\\docinfowidth}{0.9\\textwidth}
42 \\newlength{\\locallinewidth}
43 \\newcommand{\\optionlistlabel}[1]{\\bf #1 \\hfill}
44 \\newenvironment{optionlist}[1]
45 {\\begin{list}{}
46 {\\setlength{\\labelwidth}{#1}
47 \\setlength{\\rightmargin}{1cm}
48 \\setlength{\\leftmargin}{\\rightmargin}
49 \\addtolength{\\leftmargin}{\\labelwidth}
50 \\addtolength{\\leftmargin}{\\labelsep}
51 \\renewcommand{\\makelabel}{\\optionlistlabel}}
52 }{\\end{list}}
53 % begin: floats for footnotes tweaking.
54 \\setlength{\\floatsep}{0.5em}
55 \\setlength{\\textfloatsep}{\\fill}
56 \\addtolength{\\textfloatsep}{3em}
57 \\renewcommand{\\textfraction}{0.5}
58 \\renewcommand{\\topfraction}{0.5}
59 \\renewcommand{\\bottomfraction}{0.5}
60 \\setcounter{totalnumber}{50}
61 \\setcounter{topnumber}{50}
62 \\setcounter{bottomnumber}{50}
63 % end floats for footnotes
64 % some commands, that could be overwritten in the style file.
65 \\newcommand{\\rubric}[1]{\\subsection*{~\\hfill {\\it #1} \\hfill ~}}
66 \\newcommand{\\titlereference}[1]{\\textsl{#1}}
67 % end of "some commands"
68 """
70 totest = {}
72 totest['table_of_contents'] = [
73 # input
74 ["""\
75 .. contents:: Table of Contents
77 Title 1
78 =======
79 Paragraph 1.
81 Title 2
82 -------
83 Paragraph 2.
84 """,
85 ## # expected output
86 latex_head + """\
87 \\title{}
88 \\author{}
89 \\date{}
90 \\raggedbottom
91 \\begin{document}
93 \\setlength{\\locallinewidth}{\\linewidth}
94 \\hypertarget{table-of-contents}{}
95 \\pdfbookmark[0]{Table of Contents}{table-of-contents}
96 \\subsubsection*{~\\hfill Table of Contents\\hfill ~}
97 \\begin{list}{}{}
98 \\item {} \\href{\\#title-1}{Title 1}
99 \\begin{list}{}{}
100 \\item {} \\href{\#title-2}{Title 2}
102 \\end{list}
104 \\end{list}
108 %___________________________________________________________________________
110 \\hypertarget{title-1}{}
111 \\pdfbookmark[0]{Title 1}{title-1}
112 \\section*{Title 1}
114 Paragraph 1.
117 %___________________________________________________________________________
119 \\hypertarget{title-2}{}
120 \\pdfbookmark[1]{Title 2}{title-2}
121 \\subsection*{Title 2}
123 Paragraph 2.
125 \\end{document}
126 """],
131 totest['enumerated_lists'] = [
132 # input
133 ["""\
134 1. Item 1.
135 2. Second to the previous item this one will explain
137 a) nothing.
138 b) or some other.
140 3. Third is
142 (I) having pre and postfixes
143 (II) in roman numerals.
144 """,
145 # expected output
146 latex_head + """\
147 \\title{}
148 \\author{}
149 \\date{}
150 \\raggedbottom
151 \\begin{document}
153 \\setlength{\\locallinewidth}{\\linewidth}
154 \\newcounter{listcnt1}
155 \\begin{list}{\\arabic{listcnt1}.}
157 \\usecounter{listcnt1}
158 \\setlength{\\rightmargin}{\\leftmargin}
160 \\item {}
161 Item 1.
163 \\item {}
164 Second to the previous item this one will explain
166 \\end{list}
167 \\begin{quote}
168 \\newcounter{listcnt2}
169 \\begin{list}{\\alph{listcnt2})}
171 \\usecounter{listcnt2}
172 \\setlength{\\rightmargin}{\\leftmargin}
174 \\item {}
175 nothing.
177 \\item {}
178 or some other.
180 \\end{list}
181 \\end{quote}
182 \\newcounter{listcnt3}
183 \\begin{list}{\\arabic{listcnt3}.}
185 \\usecounter{listcnt3}
186 \\addtocounter{listcnt3}{2}
187 \\setlength{\\rightmargin}{\\leftmargin}
189 \\item {}
190 Third is
192 \\end{list}
193 \\begin{quote}
194 \\newcounter{listcnt4}
195 \\begin{list}{(\\Roman{listcnt4})}
197 \\usecounter{listcnt4}
198 \\setlength{\\rightmargin}{\\leftmargin}
200 \\item {}
201 having pre and postfixes
203 \\item {}
204 in roman numerals.
206 \\end{list}
207 \\end{quote}
209 \\end{document}
210 """],
213 # BUG: need to test for quote replacing if language is de (ngerman).
215 totest['quote_mangling'] = [
216 # input
217 ["""\
218 Depending on language quotes are converted for latex.
219 Expecting "en" here.
221 Inside literal blocks quotes should be left untouched
222 (use only two quotes in test code makes life easier for
223 the python interpreter running the test)::
226 This is left "untouched" also *this*.
229 .. parsed-literal::
231 should get "quotes" and *italics*.
234 Inline ``literal "quotes"`` should be kept.
235 """,
236 latex_head + """\
237 \\title{}
238 \\author{}
239 \\date{}
240 \\raggedbottom
241 \\begin{document}
243 \\setlength{\\locallinewidth}{\\linewidth}
245 Depending on language quotes are converted for latex.
246 Expecting ``en'' here.
248 Inside literal blocks quotes should be left untouched
249 (use only two quotes in test code makes life easier for
250 the python interpreter running the test):
251 \\begin{quote}{\\ttfamily \\raggedright \\noindent
252 ""~\\\\
253 This~is~left~"untouched"~also~*this*.~\\\\
255 }\\end{quote}
256 \\begin{quote}{\\ttfamily \\raggedright \\noindent
257 should~get~"quotes"~and~\\emph{italics}.
258 }\\end{quote}
260 Inline \\texttt{literal "quotes"} should be kept.
262 \\end{document}
263 """],
266 totest['table_caption'] = [
267 # input
268 ["""\
269 .. table:: Foo
271 +-----+-----+
272 | | |
273 +-----+-----+
274 | | |
275 +-----+-----+
276 """,
277 latex_head + """\
278 \\title{}
279 \\author{}
280 \\date{}
281 \\raggedbottom
282 \\begin{document}
284 \\setlength{\\locallinewidth}{\\linewidth}
286 \\begin{longtable}[c]{|p{0.07\locallinewidth}|p{0.07\locallinewidth}|}
287 \\caption{Foo}\\\\
288 \\hline
289 & \\\\
290 \hline
291 & \\\\
292 \hline
293 \\end{longtable}
295 \\end{document}
296 """],
299 # In "\\\n[" the "[" needs to be protected (otherwise it will be seen as an option to "\\").
300 totest['brackett_protection'] = [
301 # input
302 ["""\
305 something before to get a end of line.
308 the empty line gets tested too
310 """,
311 latex_head + """\
312 \\title{}
313 \\author{}
314 \\date{}
315 \\raggedbottom
316 \\begin{document}
318 \\setlength{\\locallinewidth}{\\linewidth}
319 \\begin{quote}{\\ttfamily \\raggedright \\noindent
320 something~before~to~get~a~end~of~line.~\\\\
321 {[}~\\\\
322 ~\\\\
323 the~empty~line~gets~tested~too~\\\\
325 }\\end{quote}
327 \\end{document}
328 """],
331 if __name__ == '__main__':
332 import unittest
333 unittest.main(defaultTest='suite')