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
['table_style'] = ['colwidths-auto']
28 s
.generateTests(totest_table_style_auto
)
29 settings
['table_style'] = ['booktabs']
30 s
.generateTests(totest_table_style_booktabs
)
31 settings
['stylesheet_path'] = 'data/spam,data/ham.tex'
32 s
.generateTests(totest_stylesheet
)
33 settings
['embed_stylesheet'] = True
34 settings
['warning_stream'] = ''
35 s
.generateTests(totest_stylesheet_embed
)
38 head_template
= string
.Template(
39 r
"""$head_prefix% generated by Docutils <http://docutils.sourceforge.net/>
40 \usepackage{cmap} % fix search and cut-and-paste in Acrobat
42 %%% Custom LaTeX preamble
44 %%% User specified packages and stylesheets
46 %%% Fallback definitions for Docutils-specific commands
53 head_prefix
= r
"""\documentclass[a4paper]{article}
55 requirements
= r
"""\usepackage{ifthen}
56 \usepackage[T1]{fontenc}
57 \usepackage[utf8]{inputenc}
59 latex_preamble
= r
"""% PDF Standard Fonts
60 \usepackage{mathptmx} % Times
61 \usepackage[scaled=.90]{helvet}
64 longtable
= r
"""\usepackage{longtable,ltcaption,array}
65 \setlength{\extrarowheight}{2pt}
66 \newlength{\DUtablewidth} % internal use in tables
70 fallbacks_highlight
= r
"""% basic code highlight:
71 \providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
72 \providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
73 \providecommand*\DUrolekeyword[1]{\textbf{#1}}
74 \providecommand*\DUrolestring[1]{\textit{#1}}
76 % inline markup (custom roles)
77 % \DUrole{#1}{#2} tries \DUrole#1{#2}
78 \providecommand*{\DUrole}[2]{%
79 \ifcsname DUrole#1\endcsname%
80 \csname DUrole#1\endcsname{#2}%
82 % backwards compatibility: try \docutilsrole#1{#2}
83 \ifcsname docutilsrole#1\endcsname%
84 \csname docutilsrole#1\endcsname{#2}%
93 \ifthenelse{\isundefined{\hypersetup}}{
94 \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
96 \urlstyle{same} % normal text font (alternatives: tt, rm, sf)
101 head
= head_template
.substitute(parts
)
103 head_table
= head_template
.substitute(
104 dict(parts
, requirements
= parts
['requirements'] + parts
['longtable']))
106 head_booktabs
= head_template
.substitute(
107 dict(parts
, requirements
=parts
['requirements']
108 + '\\usepackage{booktabs}\n' + parts
['longtable']))
110 head_textcomp
= head_template
.substitute(
111 dict(parts
, requirements
= parts
['requirements'] +
112 r
"""\usepackage{textcomp} % text symbol macros
115 head_alltt
= head_template
.substitute(
116 dict(parts
, requirements
= parts
['requirements'] +
117 r
"""\usepackage{alltt}
122 totest_latex_toc
= {}
123 totest_latex_sectnum
= {}
124 totest_latex_citations
= {}
125 totest_stylesheet
= {}
126 totest_stylesheet_embed
= {}
127 totest_table_style_auto
= {}
128 totest_table_style_booktabs
= {}
130 totest
['url_chars'] = [
131 ["http://nowhere/url_with%28parens%29",
133 \url{http://nowhere/url_with\%28parens\%29}
139 totest
['textcomp'] = [
140 ["2 µm is just 2/1000000 m",
142 2 µm is just 2/1000000 m
148 totest
['spanish quote'] = [
149 [".. role:: language-es\n\nUnd damit :language-es:`basta`!",
150 head_template
.substitute(dict(parts
, requirements
=
151 r
"""\usepackage{ifthen}
152 \usepackage[T1]{fontenc}
153 \usepackage[utf8]{inputenc}
154 \usepackage[spanish,english]{babel}
155 \AtBeginDocument{\shorthandoff{.<>}}
157 Und damit \foreignlanguage{spanish}{basta}!
163 totest
['code role'] = [
165 head_template
.substitute(dict(parts
, requirements
= parts
['requirements']+
166 r
"""\usepackage{color}
167 """, fallbacks
= parts
['fallbacks_highlight'])) + r
"""
168 \texttt{\DUrole{code}{x=1}}
174 totest
['table_of_contents'] = [
177 .. contents:: Table of Contents
188 head_template
.substitute(dict(parts
,
189 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n',
191 % title for topics, admonitions, unsupported section levels, and sidebar
192 \providecommand*{\DUtitle}[2][class-arg]{%
193 % call \DUtitle#1{#2} if it exists:
194 \ifcsname DUtitle#1\endcsname%
195 \csname DUtitle#1\endcsname{#2}%
197 \smallskip\noindent\textbf{#2}\smallskip%
201 \phantomsection\label{table-of-contents}
202 \pdfbookmark[1]{Table of Contents}{table-of-contents}
203 \DUtitle[contents]{Table of Contents}
206 \item \hyperref[title-1]{Title 1}
209 \item \hyperref[title-2]{Title 2}
231 totest
['footnote text'] = [
238 .. [3] 1. enumeration
241 head_template
.substitute(dict(parts
,
242 fallbacks
=r
"""% numeric or symbol footnotes with hyperlinks
243 \providecommand*{\DUfootnotemark}[3]{%
244 \raisebox{1em}{\hypertarget{#1}{}}%
245 \hyperlink{#2}{\textsuperscript{#3}}%
247 \providecommand{\DUfootnotetext}[4]{%
249 \renewcommand{\thefootnote}{%
250 \protect\raisebox{1em}{\protect\hypertarget{#1}{}}%
251 \protect\hyperlink{#2}{#3}}%
256 \DUfootnotetext{id1}{id1}{1}{%
260 \DUfootnotetext{id2}{id2}{2}{}
262 \DUfootnotetext{id3}{id3}{3}{
272 totest_latex_toc
['no_sectnum'] = [
281 head_template
.substitute(dict(parts
,
282 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
284 \phantomsection\label{contents}
285 \pdfbookmark[1]{Contents}{contents}
289 \section{first section%
290 \label{first-section}%
297 totest_latex_toc
['sectnum'] = [
307 head_template
.substitute(dict(parts
,
308 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
310 \phantomsection\label{contents}
311 \pdfbookmark[1]{Contents}{contents}
315 \section{1 first section%
316 \label{first-section}%
324 totest_latex_sectnum
['no_sectnum'] = [
333 head_template
.substitute(dict(parts
, requirements
= parts
['requirements'] +
334 r
"""\setcounter{secnumdepth}{0}
339 \section{first section%
340 \label{first-section}%
347 totest_latex_sectnum
['sectnum'] = [
358 head_template
.substitute(dict(parts
,
359 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n'
364 \section{first section%
365 \label{first-section}%
372 totest_latex_citations
['citations_with_underscore'] = [
375 Just a test citation [my_cite2006]_.
378 The underscore is mishandled.
382 Just a test citation \cite{my_cite2006}.
384 \begin{thebibliography}{my\_cite2006}
385 \bibitem[my\_cite2006]{my_cite2006}{
386 The underscore is mishandled.
388 \end{thebibliography}
395 totest_latex_citations
['adjacent_citations'] = [
398 Two non-citations: [MeYou2007]_[YouMe2007]_.
400 Need to be separated for grouping: [MeYou2007]_ [YouMe2007]_.
402 Two spaces (or anything else) for no grouping: [MeYou2007]_ [YouMe2007]_.
404 But a line break should work: [MeYou2007]_
408 .. [YouMe2007] important.
412 Two non-citations: {[}MeYou2007{]}\_{[}YouMe2007{]}\_.
414 Need to be separated for grouping: \cite{MeYou2007,YouMe2007}.
416 Two spaces (or anything else) for no grouping: \cite{MeYou2007} \cite{YouMe2007}.
418 But a line break should work: \cite{MeYou2007,YouMe2007}.
420 \begin{thebibliography}{MeYou2007}
421 \bibitem[MeYou2007]{MeYou2007}{
424 \bibitem[YouMe2007]{YouMe2007}{
427 \end{thebibliography}
434 totest
['enumerated_lists'] = [
438 2. Second to the previous item this one will explain
445 (I) having pre and postfixes
446 (II) in roman numerals.
453 \item Second to the previous item this one will explain
458 \renewcommand{\labelenumi}{\alph{enumi})}
466 \setcounter{enumi}{2}
472 \renewcommand{\labelenumi}{(\Roman{enumi})}
473 \item having pre and postfixes
475 \item in roman numerals.
483 # TODO: need to test for quote replacing if the language uses "ASCII-quotes"
484 # as active character (e.g. de (ngerman)).
487 totest
['table_caption'] = [
499 \setlength{\DUtablewidth}{\linewidth}
500 \begin{longtable}[c]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
513 totest
['table_styles'] = [
525 \setlength{\DUtablewidth}{\linewidth}
526 \begin{longtable*}[c]{p{0.075\DUtablewidth}p{0.075\DUtablewidth}}
550 \setlength{\DUtablewidth}{\linewidth}
551 \begin{longtable*}[c]{p{0.075\DUtablewidth}p{0.028\DUtablewidth}}
565 :class: colwidths-auto
572 \begin{longtable*}[c]{|l|l|}
589 \begin{longtable*}[c]{|l|l|}
606 \setlength{\DUtablewidth}{\linewidth}
607 \begin{longtable*}[c]{|p{0.191\DUtablewidth}|p{0.365\DUtablewidth}|}
621 totest_table_style_booktabs
['table_styles'] = [
622 # borderless overrides "booktabs" table_style
634 \setlength{\DUtablewidth}{\linewidth}
635 \begin{longtable*}[c]{p{0.075\DUtablewidth}p{0.075\DUtablewidth}}
659 \begin{longtable*}[c]{ll}
676 \setlength{\DUtablewidth}{\linewidth}
677 \begin{longtable*}[c]{p{0.191\DUtablewidth}p{0.365\DUtablewidth}}
690 totest_table_style_auto
['table_styles'] = [
702 \begin{longtable*}[c]{ll}
718 \begin{longtable*}[c]{ll}
726 # given width overrides "colwidth-auto"
736 \setlength{\DUtablewidth}{\linewidth}
737 \begin{longtable*}[c]{|p{0.191\DUtablewidth}|p{0.365\DUtablewidth}|}
751 totest
['table_align'] = [
762 \setlength{\DUtablewidth}{\linewidth}
763 \begin{longtable*}[r]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
777 totest
['table_empty_cells'] = [
786 \setlength{\DUtablewidth}{\linewidth}
787 \begin{longtable*}[c]{|p{0.075\DUtablewidth}|p{0.086\DUtablewidth}|}
800 \multicolumn{2}{c}{\hfill ... continued on next page} \\
821 \setlength{\DUtablewidth}{\linewidth}
822 \begin{longtable*}[c]{|p{0.063\DUtablewidth}|p{0.063\DUtablewidth}|}
830 \multicolumn{2}{|p{0.13\DUtablewidth}|}{} \\
838 # The "[" needs to be protected (otherwise it will be seen as an
839 # option to "\\", "\item", etc. ).
841 totest
['bracket_protection'] = [
844 * [no option] to this item
848 \item {[}no option{]} to this item
855 totest
['literal_block'] = [
858 Test special characters { [ \\\\ ] } in literal block::
865 Test special characters \{ {[} \textbackslash{} {]} \} in literal block:
869 \{ [ ( \textbackslash{}macro
905 totest
['title_with_inline_markup'] = [
910 This is the *Subtitle*
911 ----------------------
913 This is a *section title*
914 ~~~~~~~~~~~~~~~~~~~~~~~~~
916 This is the *document*.
918 head_template
.substitute(dict(parts
,
919 requirements
=parts
['requirements'] + '\\setcounter{secnumdepth}{0}\n',
921 % subtitle (in document title)
922 \providecommand*{\DUdocumentsubtitle}[1]{{\large #1}}
924 pdfsetup
=parts
['pdfsetup'] + r
"""\hypersetup{
925 pdftitle={This is the Title},
927 """, titledata
=r
"""\title{This is the \emph{Title}%
928 \label{this-is-the-title}%
930 \DUdocumentsubtitle{This is the \emph{Subtitle}}%
931 \label{this-is-the-subtitle}}
934 """)) + r
"""\maketitle
937 \section{This is a \emph{section title}%
938 \label{this-is-a-section-title}%
941 This is the \emph{document}.
947 totest_stylesheet
['two-styles'] = [
949 ["""two stylesheet links in the header""",
950 head_template
.substitute(dict(parts
, stylesheet
=
951 r
"""\usepackage{data/spam}
954 two stylesheet links in the header
960 totest_stylesheet_embed
['two-styles'] = [
962 ["""two stylesheets embedded in the header""",
963 head_template
.substitute(dict(parts
, stylesheet
=
964 r
"""% Cannot embed stylesheet 'data/spam.sty':
965 % No such file or directory.
966 % embedded stylesheet: data/ham.tex
967 \newcommand{\ham}{wonderful ham}
970 two stylesheets embedded in the header
976 if __name__
== '__main__':
978 unittest
.main(defaultTest
='suite')