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 # BUG: need to test for quote replacing if language is de (ngerman).
426 totest
['quote_mangling'] = [
429 Depending on language quotes are converted for latex.
432 Inside literal blocks quotes should be left untouched
433 (use only two quotes in test code makes life easier for
434 the python interpreter running the test)::
437 This is left "untouched" also *this*.
442 should get "quotes" and *italics*.
445 Inline ``literal "quotes"`` should be kept.
448 Depending on language quotes are converted for latex.
449 Expecting ``en'' here.
451 Inside literal blocks quotes should be left untouched
452 (use only two quotes in test code makes life easier for
453 the python interpreter running the test):
455 \begin{quote}{\ttfamily \raggedright \noindent
457 This~is~left~"untouched"~also~*this*.\\
462 \begin{quote}{\ttfamily \raggedright \noindent
463 should~get~"quotes"~and~\emph{italics}.
467 Inline \texttt{literal "quotes"} should be kept.
473 totest
['table_caption'] = [
485 \setlength{\DUtablewidth}{\linewidth}
486 \begin{longtable}[c]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
499 totest
['table_class'] = [
512 \setlength{\DUtablewidth}{\linewidth}
513 \begin{longtable*}[c]{p{0.075\DUtablewidth}p{0.075\DUtablewidth}}
530 # The "[" needs to be protected (otherwise it will be seen as an
531 # option to "\\", "\item", etc. ).
533 totest
['brackett_protection'] = [
538 something before to get a end of line.
541 the empty line gets tested too
545 \begin{quote}{\ttfamily \raggedright \noindent
546 something~before~to~get~a~end~of~line.\\
549 the~empty~line~gets~tested~too\\
584 totest
['title_with_inline_markup'] = [
589 This is the *Subtitle*
590 ----------------------
592 This is a *section title*
593 ~~~~~~~~~~~~~~~~~~~~~~~~~
595 This is the *document*.
597 head_template
.substitute(dict(parts
,
598 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n',
599 pdfsetup
=parts
['pdfsetup'] + r
"""\hypersetup{
600 pdftitle={This is the Title},
602 """, titledata
=r
"""%%% Title Data
603 \title{\phantomsection%
604 This is the \emph{Title}%
605 \label{this-is-the-title}%
607 \large{This is the \emph{Subtitle}}%
608 \label{this-is-the-subtitle}}
611 """)) + r
"""\maketitle
614 \section{This is a \emph{section title}%
615 \label{this-is-a-section-title}%
618 This is the \emph{document}.
624 totest_stylesheet
['two-styles'] = [
626 ["""two stylesheet links in the header""",
627 head_template
.substitute(dict(parts
, stylesheet
=
628 r
"""\usepackage{data/spam}
631 two stylesheet links in the header
637 totest_stylesheet_embed
['two-styles'] = [
639 ["""two stylesheets embedded in the header""",
640 head_template
.substitute(dict(parts
, stylesheet
=
641 r
"""% Cannot embed stylesheet 'data/spam.sty':
642 % No such file or directory.
643 % embedded stylesheet: data/ham.tex
644 \newcommand{\ham}{wonderful ham}
647 two stylesheets embedded in the header
654 if __name__
== '__main__':
656 unittest
.main(defaultTest
='suite')