5 # Author: engelbert gruber <grubert@users.sourceforge.net>
6 # Copyright: This module has been placed in the public domain.
9 Tests for latex2e writer.
13 from __init__
import DocutilsTestSupport
16 settings
= {'use_latex_toc': False}
17 s
= DocutilsTestSupport
.PublishTestSuite('latex', suite_settings
=settings
)
18 s
.generateTests(totest
)
19 settings
['use_latex_toc'] = True
20 s
.generateTests(totest_latex_toc
)
21 settings
['use_latex_toc'] = False
22 settings
['sectnum_xform'] = False
23 s
.generateTests(totest_latex_sectnum
)
24 settings
['sectnum_xform'] = True
25 settings
['use_latex_citations'] = True
26 s
.generateTests(totest_latex_citations
)
27 settings
['stylesheet_path'] = 'data/spam,data/ham.tex'
28 s
.generateTests(totest_stylesheet
)
29 settings
['embed_stylesheet'] = True
30 settings
['warning_stream'] = ''
31 s
.generateTests(totest_stylesheet_embed
)
34 head_template
= string
.Template(
35 r
"""$head_prefix% generated by Docutils <http://docutils.sourceforge.net/>
36 \usepackage{fixltx2e} % LaTeX patches, \textsubscript
37 \usepackage{cmap} % fix search and cut-and-paste in Acrobat
39 %%% Custom LaTeX preamble
41 %%% User specified packages and stylesheets
43 %%% Fallback definitions for Docutils-specific commands
51 head_prefix
= r
"""\documentclass[a4paper]{article}
53 requirements
= r
"""\usepackage{ifthen}
54 \usepackage[T1]{fontenc}
55 \usepackage[utf8]{inputenc}
57 latex_preamble
= r
"""% PDF Standard Fonts
58 \usepackage{mathptmx} % Times
59 \usepackage[scaled=.90]{helvet}
66 \ifthenelse{\isundefined{\hypersetup}}{
67 \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
68 \urlstyle{same} % normal text font (alternatives: tt, rm, sf)
73 head
= head_template
.substitute(parts
)
75 head_table
= head_template
.substitute(
76 dict(parts
, requirements
= parts
['requirements'] +
77 r
"""\usepackage{longtable,ltcaption,array}
78 \setlength{\extrarowheight}{2pt}
79 \newlength{\DUtablewidth} % internal use in tables
82 head_textcomp
= head_template
.substitute(
83 dict(parts
, requirements
= parts
['requirements'] +
84 r
"""\usepackage{textcomp} % text symbol macros
89 totest_latex_sectnum
= {}
90 totest_latex_citations
= {}
91 totest_stylesheet
= {}
92 totest_stylesheet_embed
= {}
94 totest
['url_chars'] = [
95 ["http://nowhere/url_with%28parens%29",
97 \url{http://nowhere/url_with\%28parens\%29}
103 totest
['textcomp'] = [
104 ["2 µm is just 2/1000000 m",
106 2 µm is just 2/1000000 m
112 totest
['spanish quote'] = [
113 [".. role:: language-es\n\nUnd damit :language-es:`basta`!",
114 head_template
.substitute(dict(parts
, requirements
=
115 r
"""\usepackage{ifthen}
116 \usepackage[T1]{fontenc}
117 \usepackage[utf8]{inputenc}
118 \usepackage[spanish,english]{babel}
119 \addto\shorthandsspanish{\spanishdeactivate{."~<>}}
121 Und damit \otherlanguage{spanish}{basta}!
127 totest
['table_of_contents'] = [
130 .. contents:: Table of Contents
141 head_template
.substitute(dict(parts
,
142 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n',
144 % title for topics, admonitions, unsupported section levels, and sidebar
145 \providecommand*{\DUtitle}[2][class-arg]{%
146 % call \DUtitle#1{#2} if it exists:
147 \ifcsname DUtitle#1\endcsname%
148 \csname DUtitle#1\endcsname{#2}%
150 \smallskip\noindent\textbf{#2}\smallskip%
154 \phantomsection\label{table-of-contents}
155 \pdfbookmark[1]{Table of Contents}{table-of-contents}
156 \DUtitle[contents]{Table of Contents}
160 \item \hyperref[title-1]{Title 1}
164 \item \hyperref[title-2]{Title 2}
189 totest_latex_toc
['no_sectnum'] = [
198 head_template
.substitute(dict(parts
,
199 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
201 \phantomsection\label{contents}
202 \pdfbookmark[1]{Contents}{contents}
207 \section{first section%
208 \label{first-section}%
215 totest_latex_toc
['sectnum'] = [
225 head_template
.substitute(dict(parts
,
226 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
228 \phantomsection\label{contents}
229 \pdfbookmark[1]{Contents}{contents}
234 \section{1~~~first section%
235 \label{first-section}%
243 totest_latex_sectnum
['no_sectnum'] = [
252 head_template
.substitute(dict(parts
, requirements
= parts
['requirements'] +
253 r
"""\setcounter{secnumdepth}{0}
258 \section{first section%
259 \label{first-section}%
266 totest_latex_sectnum
['sectnum'] = [
277 head_template
.substitute(dict(parts
,
278 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
283 \section{first section%
284 \label{first-section}%
291 totest_latex_citations
['citations_with_underscore'] = [
294 Just a test citation [my_cite2006]_.
297 The underscore is mishandled.
301 Just a test citation \cite{my_cite2006}.
303 \begin{thebibliography}{my\_cite2006}
304 \bibitem[my\_cite2006]{my_cite2006}{
305 The underscore is mishandled.
307 \end{thebibliography}
314 totest_latex_citations
['adjacent_citations'] = [
317 Two non-citations: [MeYou2007]_[YouMe2007]_.
319 Need to be separated for grouping: [MeYou2007]_ [YouMe2007]_.
321 Two spaces (or anything else) for no grouping: [MeYou2007]_ [YouMe2007]_.
323 But a line break should work: [MeYou2007]_
327 .. [YouMe2007] important.
331 Two non-citations: {[}MeYou2007{]}\_{[}YouMe2007{]}\_.
333 Need to be separated for grouping: \cite{MeYou2007,YouMe2007}.
335 Two spaces (or anything else) for no grouping: \cite{MeYou2007} \cite{YouMe2007}.
337 But a line break should work: \cite{MeYou2007,YouMe2007}.
339 \begin{thebibliography}{MeYou2007}
340 \bibitem[MeYou2007]{MeYou2007}{
343 \bibitem[YouMe2007]{YouMe2007}{
346 \end{thebibliography}
353 totest
['enumerated_lists'] = [
357 2. Second to the previous item this one will explain
364 (I) having pre and postfixes
365 (II) in roman numerals.
368 head
+ r
"""\newcounter{listcnt0}
369 \begin{list}{\arabic{listcnt0}.}
371 \usecounter{listcnt0}
372 \setlength{\rightmargin}{\leftmargin}
377 \item Second to the previous item this one will explain
381 \setcounter{listcnt0}{0}
382 \begin{list}{\alph{listcnt0})}
384 \usecounter{listcnt0}
385 \setlength{\rightmargin}{\leftmargin}
394 \setcounter{listcnt0}{0}
395 \begin{list}{\arabic{listcnt0}.}
397 \usecounter{listcnt0}
398 \addtocounter{listcnt0}{2}
399 \setlength{\rightmargin}{\leftmargin}
406 \setcounter{listcnt0}{0}
407 \begin{list}{(\Roman{listcnt0})}
409 \usecounter{listcnt0}
410 \setlength{\rightmargin}{\leftmargin}
413 \item having pre and postfixes
415 \item in roman numerals.
424 # TODO: need to test for quote replacing if the language uses "ASCII-quotes"
425 # as active character (e.g. de (ngerman)).
428 totest
['table_caption'] = [
440 \setlength{\DUtablewidth}{\linewidth}
441 \begin{longtable}[c]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
454 totest
['table_class'] = [
467 \setlength{\DUtablewidth}{\linewidth}
468 \begin{longtable*}[c]{p{0.075\DUtablewidth}p{0.075\DUtablewidth}}
485 # The "[" needs to be protected (otherwise it will be seen as an
486 # option to "\\", "\item", etc. ).
488 totest
['brackett_protection'] = [
493 something before to get a end of line.
496 the empty line gets tested too
500 \begin{quote}{\ttfamily \raggedright \noindent
501 something~before~to~get~a~end~of~line.\\
504 the~empty~line~gets~tested~too\\
539 totest
['title_with_inline_markup'] = [
544 This is the *Subtitle*
545 ----------------------
547 This is a *section title*
548 ~~~~~~~~~~~~~~~~~~~~~~~~~
550 This is the *document*.
552 head_template
.substitute(dict(parts
,
553 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n',
554 pdfsetup
=parts
['pdfsetup'] + r
"""\hypersetup{
555 pdftitle={This is the Title},
557 """, titledata
=r
"""%%% Title Data
558 \title{\phantomsection%
559 This is the \emph{Title}%
560 \label{this-is-the-title}%
562 \large{This is the \emph{Subtitle}}%
563 \label{this-is-the-subtitle}}
566 """)) + r
"""\maketitle
569 \section{This is a \emph{section title}%
570 \label{this-is-a-section-title}%
573 This is the \emph{document}.
579 totest_stylesheet
['two-styles'] = [
581 ["""two stylesheet links in the header""",
582 head_template
.substitute(dict(parts
, stylesheet
=
583 r
"""\usepackage{data/spam}
586 two stylesheet links in the header
592 totest_stylesheet_embed
['two-styles'] = [
594 ["""two stylesheets embedded in the header""",
595 head_template
.substitute(dict(parts
, stylesheet
=
596 r
"""% Cannot embed stylesheet 'data/spam.sty':
597 % No such file or directory.
598 % embedded stylesheet: data/ham.tex
599 \newcommand{\ham}{wonderful ham}
602 two stylesheets embedded in the header
609 if __name__
== '__main__':
611 unittest
.main(defaultTest
='suite')