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 # compatibility module for Python 2.3
14 if not hasattr(string
, 'Template'):
15 import docutils
._string
_template
_compat
16 string
.Template
= docutils
._string
_template
_compat
.Template
18 from __init__
import DocutilsTestSupport
21 settings
= {'use_latex_toc': False}
22 s
= DocutilsTestSupport
.PublishTestSuite('latex', suite_settings
=settings
)
23 s
.generateTests(totest
)
24 settings
['use_latex_toc'] = True
25 s
.generateTests(totest_latex_toc
)
26 settings
['use_latex_toc'] = False
27 settings
['sectnum_xform'] = False
28 s
.generateTests(totest_latex_sectnum
)
29 settings
['sectnum_xform'] = True
30 settings
['use_latex_citations'] = True
31 s
.generateTests(totest_latex_citations
)
32 settings
['stylesheet_path'] = 'data/spam,data/ham.tex'
33 s
.generateTests(totest_stylesheet
)
34 settings
['embed_stylesheet'] = True
35 settings
['warning_stream'] = ''
36 s
.generateTests(totest_stylesheet_embed
)
39 head_template
= string
.Template(
40 r
"""$head_prefix% generated by Docutils <http://docutils.sourceforge.net/>
41 \usepackage{fixltx2e} % LaTeX patches, \textsubscript
42 \usepackage{cmap} % fix search and cut-and-paste in Acrobat
44 %%% Custom LaTeX preamble
46 %%% User specified packages and stylesheets
48 %%% Fallback definitions for Docutils-specific commands
56 head_prefix
= r
"""\documentclass[a4paper]{article}
58 requirements
= r
"""\usepackage{ifthen}
59 \usepackage[T1]{fontenc}
60 \usepackage[utf8]{inputenc}
62 latex_preamble
= r
"""% PDF Standard Fonts
63 \usepackage{mathptmx} % Times
64 \usepackage[scaled=.90]{helvet}
71 \ifthenelse{\isundefined{\hypersetup}}{
72 \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
73 \urlstyle{same} % normal text font (alternatives: tt, rm, sf)
78 head
= head_template
.substitute(parts
)
80 head_table
= head_template
.substitute(
81 dict(parts
, requirements
= parts
['requirements'] +
82 r
"""\usepackage{longtable,ltcaption,array}
83 \setlength{\extrarowheight}{2pt}
84 \newlength{\DUtablewidth} % internal use in tables
87 head_textcomp
= head_template
.substitute(
88 dict(parts
, requirements
= parts
['requirements'] +
89 r
"""\usepackage{textcomp} % text symbol macros
94 totest_latex_sectnum
= {}
95 totest_latex_citations
= {}
96 totest_stylesheet
= {}
97 totest_stylesheet_embed
= {}
99 totest
['url_chars'] = [
100 ["http://nowhere/url_with%28parens%29",
102 \url{http://nowhere/url_with\%28parens\%29}
108 totest
['textcomp'] = [
109 ["2 µm is just 2/1000000 m",
111 2 µm is just 2/1000000 m
117 totest
['spanish quote'] = [
118 [".. role:: language-es\n\nUnd damit :language-es:`basta`!",
119 head_template
.substitute(dict(parts
, requirements
=
120 r
"""\usepackage{ifthen}
121 \usepackage[T1]{fontenc}
122 \usepackage[utf8]{inputenc}
123 \usepackage[spanish,english]{babel}
124 \addto\shorthandsspanish{\spanishdeactivate{."~<>}}
126 Und damit \otherlanguage{spanish}{basta}!
132 totest
['table_of_contents'] = [
135 .. contents:: Table of Contents
146 head_template
.substitute(dict(parts
,
147 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n',
149 % title for topics, admonitions, unsupported section levels, and sidebar
150 \providecommand*{\DUtitle}[2][class-arg]{%
151 % call \DUtitle#1{#2} if it exists:
152 \ifcsname DUtitle#1\endcsname%
153 \csname DUtitle#1\endcsname{#2}%
155 \smallskip\noindent\textbf{#2}\smallskip%
159 \phantomsection\label{table-of-contents}
160 \pdfbookmark[1]{Table of Contents}{table-of-contents}
161 \DUtitle[contents]{Table of Contents}
165 \item \hyperref[title-1]{Title 1}
169 \item \hyperref[title-2]{Title 2}
194 totest_latex_toc
['no_sectnum'] = [
203 head_template
.substitute(dict(parts
,
204 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
206 \phantomsection\label{contents}
207 \pdfbookmark[1]{Contents}{contents}
212 \section{first section%
213 \label{first-section}%
220 totest_latex_toc
['sectnum'] = [
230 head_template
.substitute(dict(parts
,
231 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
233 \phantomsection\label{contents}
234 \pdfbookmark[1]{Contents}{contents}
239 \section{1~~~first section%
240 \label{first-section}%
248 totest_latex_sectnum
['no_sectnum'] = [
257 head_template
.substitute(dict(parts
, requirements
= parts
['requirements'] +
258 r
"""\setcounter{secnumdepth}{0}
263 \section{first section%
264 \label{first-section}%
271 totest_latex_sectnum
['sectnum'] = [
282 head_template
.substitute(dict(parts
,
283 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
288 \section{first section%
289 \label{first-section}%
296 totest_latex_citations
['citations_with_underscore'] = [
299 Just a test citation [my_cite2006]_.
302 The underscore is mishandled.
306 Just a test citation \cite{my_cite2006}.
308 \begin{thebibliography}{my\_cite2006}
309 \bibitem[my\_cite2006]{my_cite2006}{
310 The underscore is mishandled.
312 \end{thebibliography}
319 totest_latex_citations
['adjacent_citations'] = [
322 Two non-citations: [MeYou2007]_[YouMe2007]_.
324 Need to be separated for grouping: [MeYou2007]_ [YouMe2007]_.
326 Two spaces (or anything else) for no grouping: [MeYou2007]_ [YouMe2007]_.
328 But a line break should work: [MeYou2007]_
332 .. [YouMe2007] important.
336 Two non-citations: {[}MeYou2007{]}\_{[}YouMe2007{]}\_.
338 Need to be separated for grouping: \cite{MeYou2007,YouMe2007}.
340 Two spaces (or anything else) for no grouping: \cite{MeYou2007} \cite{YouMe2007}.
342 But a line break should work: \cite{MeYou2007,YouMe2007}.
344 \begin{thebibliography}{MeYou2007}
345 \bibitem[MeYou2007]{MeYou2007}{
348 \bibitem[YouMe2007]{YouMe2007}{
351 \end{thebibliography}
358 totest
['enumerated_lists'] = [
362 2. Second to the previous item this one will explain
369 (I) having pre and postfixes
370 (II) in roman numerals.
373 head
+ r
"""\newcounter{listcnt0}
374 \begin{list}{\arabic{listcnt0}.}
376 \usecounter{listcnt0}
377 \setlength{\rightmargin}{\leftmargin}
382 \item Second to the previous item this one will explain
386 \setcounter{listcnt0}{0}
387 \begin{list}{\alph{listcnt0})}
389 \usecounter{listcnt0}
390 \setlength{\rightmargin}{\leftmargin}
399 \setcounter{listcnt0}{0}
400 \begin{list}{\arabic{listcnt0}.}
402 \usecounter{listcnt0}
403 \addtocounter{listcnt0}{2}
404 \setlength{\rightmargin}{\leftmargin}
411 \setcounter{listcnt0}{0}
412 \begin{list}{(\Roman{listcnt0})}
414 \usecounter{listcnt0}
415 \setlength{\rightmargin}{\leftmargin}
418 \item having pre and postfixes
420 \item in roman numerals.
429 # BUG: need to test for quote replacing if language is de (ngerman).
431 totest
['quote_mangling'] = [
434 Depending on language quotes are converted for latex.
437 Inside literal blocks quotes should be left untouched
438 (use only two quotes in test code makes life easier for
439 the python interpreter running the test)::
442 This is left "untouched" also *this*.
447 should get "quotes" and *italics*.
450 Inline ``literal "quotes"`` should be kept.
453 Depending on language quotes are converted for latex.
454 Expecting ``en'' here.
456 Inside literal blocks quotes should be left untouched
457 (use only two quotes in test code makes life easier for
458 the python interpreter running the test):
460 \begin{quote}{\ttfamily \raggedright \noindent
462 This~is~left~"untouched"~also~*this*.\\
467 \begin{quote}{\ttfamily \raggedright \noindent
468 should~get~"quotes"~and~\emph{italics}.
472 Inline \texttt{literal "quotes"} should be kept.
478 totest
['table_caption'] = [
490 \setlength{\DUtablewidth}{\linewidth}
491 \begin{longtable}[c]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
504 totest
['table_class'] = [
517 \setlength{\DUtablewidth}{\linewidth}
518 \begin{longtable*}[c]{p{0.075\DUtablewidth}p{0.075\DUtablewidth}}
535 # The "[" needs to be protected (otherwise it will be seen as an
536 # option to "\\", "\item", etc. ).
538 totest
['brackett_protection'] = [
543 something before to get a end of line.
546 the empty line gets tested too
550 \begin{quote}{\ttfamily \raggedright \noindent
551 something~before~to~get~a~end~of~line.\\
554 the~empty~line~gets~tested~too\\
589 totest
['title_with_inline_markup'] = [
594 This is the *Subtitle*
595 ----------------------
597 This is a *section title*
598 ~~~~~~~~~~~~~~~~~~~~~~~~~
600 This is the *document*.
602 head_template
.substitute(dict(parts
,
603 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n',
604 pdfsetup
=parts
['pdfsetup'] + r
"""\hypersetup{
605 pdftitle={This is the Title},
607 """, titledata
=r
"""%%% Title Data
608 \title{\phantomsection%
609 This is the \emph{Title}%
610 \label{this-is-the-title}%
612 \large{This is the \emph{Subtitle}}%
613 \label{this-is-the-subtitle}}
616 """)) + r
"""\maketitle
619 \section{This is a \emph{section title}%
620 \label{this-is-a-section-title}%
623 This is the \emph{document}.
629 totest_stylesheet
['two-styles'] = [
631 ["""two stylesheet links in the header""",
632 head_template
.substitute(dict(parts
, stylesheet
=
633 r
"""\usepackage{data/spam}
636 two stylesheet links in the header
642 totest_stylesheet_embed
['two-styles'] = [
644 ["""two stylesheets embedded in the header""",
645 head_template
.substitute(dict(parts
, stylesheet
=
646 r
"""% Cannot embed stylesheet 'data/spam.sty':
647 % No such file or directory.
648 % embedded stylesheet: data/ham.tex
649 \newcommand{\ham}{wonderful ham}
652 two stylesheets embedded in the header
659 if __name__
== '__main__':
661 unittest
.main(defaultTest
='suite')