Recognize table class: borderless, nolines, booktabs, standard.
[docutils.git] / test / test_writers / test_latex2e.py
blobff2c9d6a3d4a4df23adc49ff70ffa0a4043c696c
1 #! /usr/bin/env python
3 # $Id$
4 # Author: engelbert gruber <grubert@users.sourceforge.net>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Tests for latex2e writer.
9 """
11 from __init__ import DocutilsTestSupport
13 def suite():
14 settings = {'use_latex_toc': 0}
15 s = DocutilsTestSupport.PublishTestSuite('latex', suite_settings=settings)
16 s.generateTests(totest)
17 settings['use_latex_toc'] = 1
18 s.generateTests(totest_latex_toc)
19 return s
22 latex_head = """\
23 \\documentclass[10pt,a4paper,english]{article}
24 \\usepackage{babel}
25 \\usepackage{ae}
26 \\usepackage{aeguill}
27 \\usepackage{shortvrb}
28 \\usepackage[latin1]{inputenc}
29 \\usepackage{tabularx}
30 \\usepackage{longtable}
31 \\setlength{\\extrarowheight}{2pt}
32 \\usepackage{amsmath}
33 \\usepackage{graphicx}
34 \\usepackage{color}
35 \\usepackage{multirow}
36 \\usepackage{ifthen}
37 \\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
38 \\usepackage[DIV12]{typearea}
39 %% generator Docutils: http://docutils.sourceforge.net/
40 \\newlength{\\admonitionwidth}
41 \\setlength{\\admonitionwidth}{0.9\\textwidth}
42 \\newlength{\\docinfowidth}
43 \\setlength{\\docinfowidth}{0.9\\textwidth}
44 \\newlength{\\locallinewidth}
45 \\newcommand{\\optionlistlabel}[1]{\\bf #1 \\hfill}
46 \\newenvironment{optionlist}[1]
47 {\\begin{list}{}
48 {\\setlength{\\labelwidth}{#1}
49 \\setlength{\\rightmargin}{1cm}
50 \\setlength{\\leftmargin}{\\rightmargin}
51 \\addtolength{\\leftmargin}{\\labelwidth}
52 \\addtolength{\\leftmargin}{\\labelsep}
53 \\renewcommand{\\makelabel}{\\optionlistlabel}}
54 }{\\end{list}}
55 \\newlength{\\lineblockindentation}
56 \\setlength{\\lineblockindentation}{2.5em}
57 \\newenvironment{lineblock}[1]
58 {\\begin{list}{}
59 {\\setlength{\\partopsep}{\\parskip}
60 \\addtolength{\\partopsep}{\\baselineskip}
61 \\topsep0pt\\itemsep0.15\\baselineskip\\parsep0pt
62 \\leftmargin#1}
63 \\raggedright}
64 {\\end{list}}
65 % begin: floats for footnotes tweaking.
66 \\setlength{\\floatsep}{0.5em}
67 \\setlength{\\textfloatsep}{\\fill}
68 \\addtolength{\\textfloatsep}{3em}
69 \\renewcommand{\\textfraction}{0.5}
70 \\renewcommand{\\topfraction}{0.5}
71 \\renewcommand{\\bottomfraction}{0.5}
72 \\setcounter{totalnumber}{50}
73 \\setcounter{topnumber}{50}
74 \\setcounter{bottomnumber}{50}
75 % end floats for footnotes
76 % some commands, that could be overwritten in the style file.
77 \\newcommand{\\rubric}[1]{\\subsection*{~\\hfill {\\it #1} \\hfill ~}}
78 \\newcommand{\\titlereference}[1]{\\textsl{#1}}
79 % end of "some commands"
80 """
82 totest = {}
83 totest_latex_toc = {}
85 totest['table_of_contents'] = [
86 # input
87 ["""\
88 .. contents:: Table of Contents
90 Title 1
91 =======
92 Paragraph 1.
94 Title 2
95 -------
96 Paragraph 2.
97 """,
98 ## # expected output
99 latex_head + """\
100 \\title{}
101 \\author{}
102 \\date{}
103 \\raggedbottom
104 \\begin{document}
106 \\setlength{\\locallinewidth}{\\linewidth}
107 \\hypertarget{table-of-contents}{}
108 \\pdfbookmark[0]{Table of Contents}{table-of-contents}
109 \\subsubsection*{~\\hfill Table of Contents\\hfill ~}
110 \\begin{list}{}{}
111 \\item {} \\href{\\#title-1}{Title 1}
112 \\begin{list}{}{}
113 \\item {} \\href{\#title-2}{Title 2}
115 \\end{list}
117 \\end{list}
121 %___________________________________________________________________________
123 \\hypertarget{title-1}{}
124 \\pdfbookmark[0]{Title 1}{title-1}
125 \\section*{Title 1}
127 Paragraph 1.
130 %___________________________________________________________________________
132 \\hypertarget{title-2}{}
133 \\pdfbookmark[1]{Title 2}{title-2}
134 \\subsection*{Title 2}
136 Paragraph 2.
138 \\end{document}
139 """],
143 totest_latex_toc['table_of_contents'] = [
144 # input
145 ["""\
146 .. contents:: Table of Contents
148 Title 1
149 =======
150 Paragraph 1.
152 Title 2
153 -------
154 Paragraph 2.
155 """,
156 ## # expected output
157 latex_head + """\
158 \\title{}
159 \\author{}
160 \\date{}
161 \\raggedbottom
162 \\begin{document}
164 \\setlength{\\locallinewidth}{\\linewidth}
165 \\hypertarget{table-of-contents}{}
166 \\renewcommand{\contentsname}{Table of Contents}
167 \\tableofcontents
169 \\bigskip
172 %___________________________________________________________________________
174 \\hypertarget{title-1}{}
175 \\section{Title 1}
177 Paragraph 1.
180 %___________________________________________________________________________
182 \\hypertarget{title-2}{}
183 \\subsection{Title 2}
185 Paragraph 2.
187 \\end{document}
188 """],
193 totest['enumerated_lists'] = [
194 # input
195 ["""\
196 1. Item 1.
197 2. Second to the previous item this one will explain
199 a) nothing.
200 b) or some other.
202 3. Third is
204 (I) having pre and postfixes
205 (II) in roman numerals.
206 """,
207 # expected output
208 latex_head + """\
209 \\title{}
210 \\author{}
211 \\date{}
212 \\raggedbottom
213 \\begin{document}
215 \\setlength{\\locallinewidth}{\\linewidth}
216 \\newcounter{listcnt0}
217 \\begin{list}{\\arabic{listcnt0}.}
219 \\usecounter{listcnt0}
220 \\setlength{\\rightmargin}{\\leftmargin}
222 \\item {}
223 Item 1.
225 \\item {}
226 Second to the previous item this one will explain
228 \\end{list}
229 \\begin{quote}
230 \\setcounter{listcnt0}{0}
231 \\begin{list}{\\alph{listcnt0})}
233 \\usecounter{listcnt0}
234 \\setlength{\\rightmargin}{\\leftmargin}
236 \\item {}
237 nothing.
239 \\item {}
240 or some other.
242 \\end{list}
243 \\end{quote}
244 \\setcounter{listcnt0}{0}
245 \\begin{list}{\\arabic{listcnt0}.}
247 \\usecounter{listcnt0}
248 \\addtocounter{listcnt0}{2}
249 \\setlength{\\rightmargin}{\\leftmargin}
251 \\item {}
252 Third is
254 \\end{list}
255 \\begin{quote}
256 \\setcounter{listcnt0}{0}
257 \\begin{list}{(\\Roman{listcnt0})}
259 \\usecounter{listcnt0}
260 \\setlength{\\rightmargin}{\\leftmargin}
262 \\item {}
263 having pre and postfixes
265 \\item {}
266 in roman numerals.
268 \\end{list}
269 \\end{quote}
271 \\end{document}
272 """],
275 # BUG: need to test for quote replacing if language is de (ngerman).
277 totest['quote_mangling'] = [
278 # input
279 ["""\
280 Depending on language quotes are converted for latex.
281 Expecting "en" here.
283 Inside literal blocks quotes should be left untouched
284 (use only two quotes in test code makes life easier for
285 the python interpreter running the test)::
288 This is left "untouched" also *this*.
291 .. parsed-literal::
293 should get "quotes" and *italics*.
296 Inline ``literal "quotes"`` should be kept.
297 """,
298 latex_head + """\
299 \\title{}
300 \\author{}
301 \\date{}
302 \\raggedbottom
303 \\begin{document}
305 \\setlength{\\locallinewidth}{\\linewidth}
307 Depending on language quotes are converted for latex.
308 Expecting ``en'' here.
310 Inside literal blocks quotes should be left untouched
311 (use only two quotes in test code makes life easier for
312 the python interpreter running the test):
313 \\begin{quote}{\\ttfamily \\raggedright \\noindent
314 "{}"~\\\\
315 This~is~left~"untouched"~also~*this*.~\\\\
316 "{}"
317 }\\end{quote}
318 \\begin{quote}{\\ttfamily \\raggedright \\noindent
319 should~get~"quotes"~and~\\emph{italics}.
320 }\\end{quote}
322 Inline \\texttt{literal "quotes"} should be kept.
324 \\end{document}
325 """],
328 totest['table_caption'] = [
329 # input
330 ["""\
331 .. table:: Foo
333 +-----+-----+
334 | | |
335 +-----+-----+
336 | | |
337 +-----+-----+
338 """,
339 latex_head + """\
340 \\title{}
341 \\author{}
342 \\date{}
343 \\raggedbottom
344 \\begin{document}
346 \\setlength{\\locallinewidth}{\\linewidth}
348 \\begin{longtable}[c]{|p{0.07\locallinewidth}|p{0.07\locallinewidth}|}
349 \\caption{Foo}\\\\
350 \\hline
351 & \\\\
352 \hline
353 & \\\\
354 \hline
355 \\end{longtable}
357 \\end{document}
358 """],
361 totest['table_class'] = [
362 # input
363 ["""\
364 .. table::
365 :class: borderless
367 +-----+-----+
368 | 1 | 2 |
369 +-----+-----+
370 | 3 | 4 |
371 +-----+-----+
372 """,
373 latex_head + """\
374 \\title{}
375 \\author{}
376 \\date{}
377 \\raggedbottom
378 \\begin{document}
380 \\setlength{\\locallinewidth}{\\linewidth}
382 \\begin{longtable}[c]{p{0.07\locallinewidth}p{0.07\locallinewidth}}
387 \\\\
392 \\\\
393 \\end{longtable}
395 \\end{document}
396 """],
399 # In "\\\n[" the "[" needs to be protected (otherwise it will be seen as an option to "\\").
400 totest['brackett_protection'] = [
401 # input
402 ["""\
405 something before to get a end of line.
408 the empty line gets tested too
410 """,
411 latex_head + """\
412 \\title{}
413 \\author{}
414 \\date{}
415 \\raggedbottom
416 \\begin{document}
418 \\setlength{\\locallinewidth}{\\linewidth}
419 \\begin{quote}{\\ttfamily \\raggedright \\noindent
420 something~before~to~get~a~end~of~line.~\\\\
421 {[}~\\\\
422 ~\\\\
423 the~empty~line~gets~tested~too~\\\\
425 }\\end{quote}
427 \\end{document}
428 """],
431 totest['raw'] = [
432 ["""\
433 .. raw:: latex
435 \\noindent
437 A paragraph.
439 .. |sub| raw:: latex
441 (some raw text)
443 Foo |sub|
444 same paragraph.
445 """,
446 latex_head + """\
447 \\title{}
448 \\author{}
449 \\date{}
450 \\raggedbottom
451 \\begin{document}
453 \\setlength{\\locallinewidth}{\\linewidth}
454 \\noindent
455 A paragraph.
457 Foo (some raw text)
458 same paragraph.
460 \\end{document}
461 """],
464 if __name__ == '__main__':
465 import unittest
466 unittest.main(defaultTest='suite')