1 # -*- coding: utf-8 -*-
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}
64 fallbacks_highlight
= r
"""% basic code highlight:
65 \providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
66 \providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
67 \providecommand*\DUrolekeyword[1]{\textbf{#1}}
68 \providecommand*\DUrolestring[1]{\textit{#1}}
70 % inline markup (custom roles)
71 % \DUrole{#1}{#2} tries \DUrole#1{#2}
72 \providecommand*{\DUrole}[2]{%
73 \ifcsname DUrole#1\endcsname%
74 \csname DUrole#1\endcsname{#2}%
75 \else% backwards compatibility: try \docutilsrole#1{#2}
76 \ifcsname docutilsrole#1\endcsname%
77 \csname docutilsrole#1\endcsname{#2}%
86 \ifthenelse{\isundefined{\hypersetup}}{
87 \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
88 \urlstyle{same} % normal text font (alternatives: tt, rm, sf)
93 head
= head_template
.substitute(parts
)
95 head_table
= head_template
.substitute(
96 dict(parts
, requirements
= parts
['requirements'] +
97 r
"""\usepackage{longtable,ltcaption,array}
98 \setlength{\extrarowheight}{2pt}
99 \newlength{\DUtablewidth} % internal use in tables
102 head_textcomp
= head_template
.substitute(
103 dict(parts
, requirements
= parts
['requirements'] +
104 r
"""\usepackage{textcomp} % text symbol macros
108 totest_latex_toc
= {}
109 totest_latex_sectnum
= {}
110 totest_latex_citations
= {}
111 totest_stylesheet
= {}
112 totest_stylesheet_embed
= {}
114 totest
['url_chars'] = [
115 ["http://nowhere/url_with%28parens%29",
117 \url{http://nowhere/url_with\%28parens\%29}
123 totest
['textcomp'] = [
124 ["2 µm is just 2/1000000 m",
126 2 µm is just 2/1000000 m
132 totest
['spanish quote'] = [
133 [".. role:: language-es\n\nUnd damit :language-es:`basta`!",
134 head_template
.substitute(dict(parts
, requirements
=
135 r
"""\usepackage{ifthen}
136 \usepackage[T1]{fontenc}
137 \usepackage[utf8]{inputenc}
138 \usepackage[spanish,english]{babel}
139 \AtBeginDocument{\shorthandoff{.<>}}
141 Und damit \foreignlanguage{spanish}{basta}!
147 totest
['code role'] = [
149 head_template
.substitute(dict(parts
, requirements
= parts
['requirements']+
150 r
"""\usepackage{color}
151 """, fallbacks
= parts
['fallbacks_highlight'])) + r
"""
152 \texttt{\DUrole{code}{x=1}}
158 totest
['table_of_contents'] = [
161 .. contents:: Table of Contents
172 head_template
.substitute(dict(parts
,
173 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n',
175 % title for topics, admonitions, unsupported section levels, and sidebar
176 \providecommand*{\DUtitle}[2][class-arg]{%
177 % call \DUtitle#1{#2} if it exists:
178 \ifcsname DUtitle#1\endcsname%
179 \csname DUtitle#1\endcsname{#2}%
181 \smallskip\noindent\textbf{#2}\smallskip%
185 \phantomsection\label{table-of-contents}
186 \pdfbookmark[1]{Table of Contents}{table-of-contents}
187 \DUtitle[contents]{Table of Contents}
191 \item \hyperref[title-1]{Title 1}
195 \item \hyperref[title-2]{Title 2}
220 totest_latex_toc
['no_sectnum'] = [
229 head_template
.substitute(dict(parts
,
230 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
232 \phantomsection\label{contents}
233 \pdfbookmark[1]{Contents}{contents}
238 \section{first section%
239 \label{first-section}%
246 totest_latex_toc
['sectnum'] = [
256 head_template
.substitute(dict(parts
,
257 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
259 \phantomsection\label{contents}
260 \pdfbookmark[1]{Contents}{contents}
265 \section{1~~~first section%
266 \label{first-section}%
274 totest_latex_sectnum
['no_sectnum'] = [
283 head_template
.substitute(dict(parts
, requirements
= parts
['requirements'] +
284 r
"""\setcounter{secnumdepth}{0}
289 \section{first section%
290 \label{first-section}%
297 totest_latex_sectnum
['sectnum'] = [
308 head_template
.substitute(dict(parts
,
309 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
314 \section{first section%
315 \label{first-section}%
322 totest_latex_citations
['citations_with_underscore'] = [
325 Just a test citation [my_cite2006]_.
328 The underscore is mishandled.
332 Just a test citation \cite{my_cite2006}.
334 \begin{thebibliography}{my\_cite2006}
335 \bibitem[my\_cite2006]{my_cite2006}{
336 The underscore is mishandled.
338 \end{thebibliography}
345 totest_latex_citations
['adjacent_citations'] = [
348 Two non-citations: [MeYou2007]_[YouMe2007]_.
350 Need to be separated for grouping: [MeYou2007]_ [YouMe2007]_.
352 Two spaces (or anything else) for no grouping: [MeYou2007]_ [YouMe2007]_.
354 But a line break should work: [MeYou2007]_
358 .. [YouMe2007] important.
362 Two non-citations: {[}MeYou2007{]}\_{[}YouMe2007{]}\_.
364 Need to be separated for grouping: \cite{MeYou2007,YouMe2007}.
366 Two spaces (or anything else) for no grouping: \cite{MeYou2007} \cite{YouMe2007}.
368 But a line break should work: \cite{MeYou2007,YouMe2007}.
370 \begin{thebibliography}{MeYou2007}
371 \bibitem[MeYou2007]{MeYou2007}{
374 \bibitem[YouMe2007]{YouMe2007}{
377 \end{thebibliography}
384 totest
['enumerated_lists'] = [
388 2. Second to the previous item this one will explain
395 (I) having pre and postfixes
396 (II) in roman numerals.
399 head
+ r
"""\newcounter{listcnt0}
400 \begin{list}{\arabic{listcnt0}.}
402 \usecounter{listcnt0}
403 \setlength{\rightmargin}{\leftmargin}
408 \item Second to the previous item this one will explain
412 \setcounter{listcnt0}{0}
413 \begin{list}{\alph{listcnt0})}
415 \usecounter{listcnt0}
416 \setlength{\rightmargin}{\leftmargin}
425 \setcounter{listcnt0}{0}
426 \begin{list}{\arabic{listcnt0}.}
428 \usecounter{listcnt0}
429 \addtocounter{listcnt0}{2}
430 \setlength{\rightmargin}{\leftmargin}
437 \setcounter{listcnt0}{0}
438 \begin{list}{(\Roman{listcnt0})}
440 \usecounter{listcnt0}
441 \setlength{\rightmargin}{\leftmargin}
444 \item having pre and postfixes
446 \item in roman numerals.
455 # TODO: need to test for quote replacing if the language uses "ASCII-quotes"
456 # as active character (e.g. de (ngerman)).
459 totest
['table_caption'] = [
471 \setlength{\DUtablewidth}{\linewidth}
472 \begin{longtable}[c]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
485 totest
['table_class'] = [
498 \setlength{\DUtablewidth}{\linewidth}
499 \begin{longtable*}[c]{p{0.075\DUtablewidth}p{0.075\DUtablewidth}}
516 # The "[" needs to be protected (otherwise it will be seen as an
517 # option to "\\", "\item", etc. ).
519 totest
['bracket_protection'] = [
524 something before to get a end of line.
527 the empty line gets tested too
531 \begin{quote}{\ttfamily \raggedright \noindent
532 something~before~to~get~a~end~of~line.\\
535 the~empty~line~gets~tested~too\\
570 totest
['title_with_inline_markup'] = [
575 This is the *Subtitle*
576 ----------------------
578 This is a *section title*
579 ~~~~~~~~~~~~~~~~~~~~~~~~~
581 This is the *document*.
583 head_template
.substitute(dict(parts
,
584 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n',
586 % subtitle (in document title)
587 \providecommand*{\DUdocumentsubtitle}[1]{{\large #1}}
589 pdfsetup
=parts
['pdfsetup'] + r
"""\hypersetup{
590 pdftitle={This is the Title},
592 """, titledata
=r
"""%%% Title Data
593 \title{\phantomsection%
594 This is the \emph{Title}%
595 \label{this-is-the-title}%
597 \DUdocumentsubtitle{This is the \emph{Subtitle}}%
598 \label{this-is-the-subtitle}}
601 """)) + r
"""\maketitle
604 \section{This is a \emph{section title}%
605 \label{this-is-a-section-title}%
608 This is the \emph{document}.
614 totest_stylesheet
['two-styles'] = [
616 ["""two stylesheet links in the header""",
617 head_template
.substitute(dict(parts
, stylesheet
=
618 r
"""\usepackage{data/spam}
621 two stylesheet links in the header
627 totest_stylesheet_embed
['two-styles'] = [
629 ["""two stylesheets embedded in the header""",
630 head_template
.substitute(dict(parts
, stylesheet
=
631 r
"""% Cannot embed stylesheet 'data/spam.sty':
632 % No such file or directory.
633 % embedded stylesheet: data/ham.tex
634 \newcommand{\ham}{wonderful ham}
637 two stylesheets embedded in the header
643 if __name__
== '__main__':
645 unittest
.main(defaultTest
='suite')