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
, fallbacks
= r
"""
147 % title for topics, admonitions and sidebar
148 \providecommand*{\DUtitle}[2][class-arg]{%
149 % call \DUtitle#1{#2} if it exists:
150 \ifcsname DUtitle#1\endcsname%
151 \csname DUtitle#1\endcsname{#2}%
153 \smallskip\noindent\textbf{#2}\smallskip%
157 \phantomsection\label{table-of-contents}
158 \pdfbookmark[1]{Table of Contents}{table-of-contents}
159 \DUtitle[contents]{Table of Contents}
163 \item \hyperref[title-1]{Title 1}
167 \item \hyperref[title-2]{Title 2}
174 %___________________________________________________________________________
176 \section*{\phantomsection%
178 \addcontentsline{toc}{section}{Title 1}%
185 %___________________________________________________________________________
187 \subsection*{\phantomsection%
189 \addcontentsline{toc}{subsection}{Title 2}%
200 totest_latex_toc
['no_sectnum'] = [
210 \phantomsection\label{contents}
211 \pdfbookmark[1]{Contents}{contents}
216 %___________________________________________________________________________
218 \section*{\phantomsection%
220 \addcontentsline{toc}{section}{first section}%
221 \label{first-section}%
228 totest_latex_toc
['sectnum'] = [
239 \phantomsection\label{contents}
240 \pdfbookmark[1]{Contents}{contents}
245 %___________________________________________________________________________
247 \section*{\phantomsection%
249 \addcontentsline{toc}{section}{1~~~first section}%
250 \label{first-section}%
258 totest_latex_sectnum
['no_sectnum'] = [
267 head_template
.substitute(dict(parts
, requirements
= parts
['requirements'] +
268 r
"""\setcounter{secnumdepth}{0}
273 %___________________________________________________________________________
275 \section{first section%
276 \label{first-section}%
283 totest_latex_sectnum
['sectnum'] = [
298 %___________________________________________________________________________
300 \section{first section%
301 \label{first-section}%
308 totest_latex_citations
['citations_with_underscore'] = [
311 Just a test citation [my_cite2006]_.
314 The underscore is mishandled.
318 Just a test citation \cite{my_cite2006}.
320 \begin{thebibliography}{my\_cite2006}
321 \bibitem[my\_cite2006]{my_cite2006}{
322 The underscore is mishandled.
324 \end{thebibliography}
331 totest_latex_citations
['adjacent_citations'] = [
334 Two non-citations: [MeYou2007]_[YouMe2007]_.
336 Need to be separated for grouping: [MeYou2007]_ [YouMe2007]_.
338 Two spaces (or anything else) for no grouping: [MeYou2007]_ [YouMe2007]_.
340 But a line break should work: [MeYou2007]_
344 .. [YouMe2007] important.
348 Two non-citations: {[}MeYou2007{]}\_{[}YouMe2007{]}\_.
350 Need to be separated for grouping: \cite{MeYou2007,YouMe2007}.
352 Two spaces (or anything else) for no grouping: \cite{MeYou2007} \cite{YouMe2007}.
354 But a line break should work: \cite{MeYou2007,YouMe2007}.
356 \begin{thebibliography}{MeYou2007}
357 \bibitem[MeYou2007]{MeYou2007}{
360 \bibitem[YouMe2007]{YouMe2007}{
363 \end{thebibliography}
370 totest
['enumerated_lists'] = [
374 2. Second to the previous item this one will explain
381 (I) having pre and postfixes
382 (II) in roman numerals.
385 head
+ r
"""\newcounter{listcnt0}
386 \begin{list}{\arabic{listcnt0}.}
388 \usecounter{listcnt0}
389 \setlength{\rightmargin}{\leftmargin}
394 \item Second to the previous item this one will explain
398 \setcounter{listcnt0}{0}
399 \begin{list}{\alph{listcnt0})}
401 \usecounter{listcnt0}
402 \setlength{\rightmargin}{\leftmargin}
411 \setcounter{listcnt0}{0}
412 \begin{list}{\arabic{listcnt0}.}
414 \usecounter{listcnt0}
415 \addtocounter{listcnt0}{2}
416 \setlength{\rightmargin}{\leftmargin}
423 \setcounter{listcnt0}{0}
424 \begin{list}{(\Roman{listcnt0})}
426 \usecounter{listcnt0}
427 \setlength{\rightmargin}{\leftmargin}
430 \item having pre and postfixes
432 \item in roman numerals.
441 # BUG: need to test for quote replacing if language is de (ngerman).
443 totest
['quote_mangling'] = [
446 Depending on language quotes are converted for latex.
449 Inside literal blocks quotes should be left untouched
450 (use only two quotes in test code makes life easier for
451 the python interpreter running the test)::
454 This is left "untouched" also *this*.
459 should get "quotes" and *italics*.
462 Inline ``literal "quotes"`` should be kept.
465 Depending on language quotes are converted for latex.
466 Expecting ``en'' here.
468 Inside literal blocks quotes should be left untouched
469 (use only two quotes in test code makes life easier for
470 the python interpreter running the test):
472 \begin{quote}{\ttfamily \raggedright \noindent
474 This~is~left~"untouched"~also~*this*.\\
479 \begin{quote}{\ttfamily \raggedright \noindent
480 should~get~"quotes"~and~\emph{italics}.
484 Inline \texttt{literal "quotes"} should be kept.
490 totest
['table_caption'] = [
502 \setlength{\DUtablewidth}{\linewidth}
503 \begin{longtable}[c]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
516 totest
['table_class'] = [
529 \setlength{\DUtablewidth}{\linewidth}
530 \begin{longtable*}[c]{p{0.075\DUtablewidth}p{0.075\DUtablewidth}}
547 # The "[" needs to be protected (otherwise it will be seen as an
548 # option to "\\", "\item", etc. ).
550 totest
['brackett_protection'] = [
555 something before to get a end of line.
558 the empty line gets tested too
562 \begin{quote}{\ttfamily \raggedright \noindent
563 something~before~to~get~a~end~of~line.\\
566 the~empty~line~gets~tested~too\\
601 totest
['title_with_inline_markup'] = [
606 This is the *Subtitle*
607 ----------------------
609 This is a *section title*
610 ~~~~~~~~~~~~~~~~~~~~~~~~~
612 This is the *document*.
614 head_template
.substitute(
615 dict(parts
, pdfsetup
=parts
['pdfsetup'] + r
"""\hypersetup{
616 pdftitle={This is the Title},
618 """, titledata
=r
"""%%% Title Data
619 \title{\phantomsection%
620 This is the \emph{Title}%
621 \label{this-is-the-title}%
623 \large{This is the \emph{Subtitle}}%
624 \label{this-is-the-subtitle}}
627 """)) + r
"""\maketitle
630 %___________________________________________________________________________
632 \section*{\phantomsection%
633 This is a \emph{section title}%
634 \addcontentsline{toc}{section}{This is a section title}%
635 \label{this-is-a-section-title}%
638 This is the \emph{document}.
644 totest_stylesheet
['two-styles'] = [
646 ["""two stylesheet links in the header""",
647 head_template
.substitute(dict(parts
, stylesheet
=
648 r
"""\usepackage{data/spam}
651 two stylesheet links in the header
657 totest_stylesheet_embed
['two-styles'] = [
659 ["""two stylesheets embedded in the header""",
660 head_template
.substitute(dict(parts
, stylesheet
=
661 r
"""% Cannot embed stylesheet 'data/spam.sty':
662 % No such file or directory.
663 % embedded stylesheet: data/ham.tex
664 \newcommand{\ham}{wonderful ham}
667 two stylesheets embedded in the header
674 if __name__
== '__main__':
676 unittest
.main(defaultTest
='suite')