Fix behaviour of get_stylesheet_list()
[docutils.git] / docutils / test / test_writers / test_latex2e.py
blobb1bfee605692719e9432fc1345f721f44d0a614e
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # $Id$
5 # Author: engelbert gruber <grubert@users.sourceforge.net>
6 # Copyright: This module has been placed in the public domain.
8 """
9 Tests for latex2e writer.
10 """
11 from __future__ import absolute_import
13 import string
15 if __name__ == '__main__':
16 import __init__
17 from test_transforms import DocutilsTestSupport # before importing docutils!
20 def suite():
21 settings = {'use_latex_toc': False,
22 # avoid latex writer future warnings:
23 'use_latex_citations': False,
24 'legacy_column_widths': True,
26 s = DocutilsTestSupport.PublishTestSuite('latex', suite_settings=settings)
27 s.generateTests(totest)
28 settings['use_latex_toc'] = True
29 s.generateTests(totest_latex_toc)
30 settings['documentclass'] = 'book'
31 s.generateTests(totest_latex_toc_book)
32 del settings['documentclass']
33 settings['use_latex_toc'] = False
34 settings['sectnum_xform'] = False
35 s.generateTests(totest_latex_sectnum)
36 settings['sectnum_xform'] = True
37 settings['use_latex_citations'] = True
38 s.generateTests(totest_latex_citations)
39 settings['table_style'] = ['colwidths-auto']
40 s.generateTests(totest_table_style_auto)
41 settings['table_style'] = ['booktabs']
42 s.generateTests(totest_table_style_booktabs)
43 settings['stylesheet_path'] = 'data/spam,data/ham.tex'
44 s.generateTests(totest_stylesheet)
45 settings['embed_stylesheet'] = True
46 settings['warning_stream'] = ''
47 s.generateTests(totest_stylesheet_embed)
48 return s
50 head_template = string.Template(
51 r"""$head_prefix% generated by Docutils <http://docutils.sourceforge.net/>
52 \usepackage{cmap} % fix search and cut-and-paste in Acrobat
53 $requirements
54 %%% Custom LaTeX preamble
55 $latex_preamble
56 %%% User specified packages and stylesheets
57 $stylesheet
58 %%% Fallback definitions for Docutils-specific commands
59 $fallbacks$pdfsetup
60 %%% Body
61 \begin{document}
62 $titledata""")
64 parts = dict(
65 head_prefix = r"""\documentclass[a4paper]{article}
66 """,
67 requirements = r"""\usepackage{ifthen}
68 \usepackage[T1]{fontenc}
69 \usepackage[utf8]{inputenc}
70 """,
71 latex_preamble = r"""% PDF Standard Fonts
72 \usepackage{mathptmx} % Times
73 \usepackage[scaled=.90]{helvet}
74 \usepackage{courier}
75 """,
76 longtable = r"""\usepackage{longtable,ltcaption,array}
77 \setlength{\extrarowheight}{2pt}
78 \newlength{\DUtablewidth} % internal use in tables
79 """,
80 stylesheet = '',
81 fallbacks = '',
82 fallbacks_highlight = r"""
83 % basic code highlight:
84 \providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
85 \providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
86 \providecommand*\DUrolekeyword[1]{\textbf{#1}}
87 \providecommand*\DUrolestring[1]{\textit{#1}}
89 % custom inline roles: \DUrole{#1}{#2} tries \DUrole#1{#2}
90 \providecommand*{\DUrole}[2]{%
91 \ifcsname DUrole#1\endcsname%
92 \csname DUrole#1\endcsname{#2}%
93 \else%
94 #2%
95 \fi%
97 """,
98 pdfsetup = r"""
99 % hyperlinks:
100 \ifthenelse{\isundefined{\hypersetup}}{
101 \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
102 \usepackage{bookmark}
103 \urlstyle{same} % normal text font (alternatives: tt, rm, sf)
105 """,
106 titledata = '')
108 head = head_template.substitute(parts)
110 head_table = head_template.substitute(
111 dict(parts, requirements = parts['requirements'] + parts['longtable']))
113 head_booktabs = head_template.substitute(
114 dict(parts, requirements=parts['requirements']
115 + '\\usepackage{booktabs}\n' + parts['longtable']))
117 head_textcomp = head_template.substitute(
118 dict(parts, requirements = parts['requirements'] +
119 r"""\usepackage{textcomp} % text symbol macros
120 """))
122 head_alltt = head_template.substitute(
123 dict(parts, requirements = parts['requirements'] +
124 r"""\usepackage{alltt}
125 """))
128 totest = {}
129 totest_latex_toc = {}
130 totest_latex_toc_book = {}
131 totest_latex_sectnum = {}
132 totest_latex_citations = {}
133 totest_stylesheet = {}
134 totest_stylesheet_embed = {}
135 totest_table_style_auto = {}
136 totest_table_style_booktabs = {}
138 totest['url_chars'] = [
139 ["http://nowhere/url_with%28parens%29",
140 head + r"""
141 \url{http://nowhere/url_with\%28parens\%29}
143 \end{document}
144 """],
147 totest['textcomp'] = [
148 ["2 µm is just 2/1000000 m",
149 head_textcomp + r"""
150 2 µm is just 2/1000000 m
152 \end{document}
153 """],
156 totest['spanish quote'] = [
157 [".. role:: language-es\n\nUnd damit :language-es:`basta`!",
158 head_template.substitute(dict(parts, requirements =
159 r"""\usepackage{ifthen}
160 \usepackage[T1]{fontenc}
161 \usepackage[utf8]{inputenc}
162 \usepackage[spanish,english]{babel}
163 \AtBeginDocument{\shorthandoff{.<>}}
164 """)) + r"""
165 Und damit \foreignlanguage{spanish}{basta}!
167 \end{document}
168 """],
171 totest['code role'] = [
172 [":code:`x=1`",
173 head_template.substitute(dict(parts, requirements = parts['requirements']+
174 r"""\usepackage{color}
175 """, fallbacks = parts['fallbacks_highlight'])) + r"""
176 \texttt{\DUrole{code}{x=1}}
178 \end{document}
179 """],
182 totest['table_of_contents'] = [
183 # input
184 ["""\
185 .. contents:: Table of Contents
187 Title 1
188 =======
189 Paragraph 1.
191 Title 2
192 -------
193 Paragraph 2.
194 """,
195 # expected output
196 head_template.substitute(dict(parts,
197 requirements=parts['requirements'] + '\\setcounter{secnumdepth}{0}\n',
198 fallbacks=r"""
199 % class handling for environments (block-level elements)
200 % \begin{DUclass}{spam} tries \DUCLASSspam and
201 % \end{DUclass}{spam} tries \endDUCLASSspam
202 \ifx\DUclass\undefined % poor man's "provideenvironment"
203 \newenvironment{DUclass}[1]%
204 {% "#1" does not work in end-part of environment.
205 \def\DocutilsClassFunctionName{DUCLASS#1}
206 \csname \DocutilsClassFunctionName \endcsname}%
207 {\csname end\DocutilsClassFunctionName \endcsname}%
210 % title for topics, admonitions, unsupported section levels, and sidebar
211 \providecommand*{\DUtitle}[1]{%
212 \smallskip\noindent\textbf{#1}\smallskip}
214 \providecommand*{\DUCLASScontents}{%
215 \renewenvironment{itemize}%
216 {\begin{list}{}{\setlength{\partopsep}{0pt}
217 \setlength{\parsep}{0pt}}
219 {\end{list}}%
221 """)) + r"""
222 \phantomsection\label{table-of-contents}
223 \pdfbookmark[1]{Table of Contents}{table-of-contents}
225 \begin{DUclass}{contents}
227 \DUtitle{Table of Contents}
229 \begin{itemize}
230 \item \hyperref[title-1]{Title 1}
232 \begin{itemize}
233 \item \hyperref[title-2]{Title 2}
234 \end{itemize}
235 \end{itemize}
236 \end{DUclass}
239 \section{Title 1%
240 \label{title-1}%
243 Paragraph 1.
246 \subsection{Title 2%
247 \label{title-2}%
250 Paragraph 2.
252 \end{document}
253 """],
256 totest['footnote text'] = [
257 # input
258 ["""\
259 .. [1] paragraph
261 .. [2]
263 .. [3] 1. enumeration
264 """,
265 # expected output
266 head_template.substitute(dict(parts,
267 fallbacks=r"""
268 % numerical or symbol footnotes with hyperlinks and backlinks
269 \providecommand*{\DUfootnotemark}[3]{%
270 \raisebox{1em}{\hypertarget{#1}{}}%
271 \hyperlink{#2}{\textsuperscript{#3}}%
273 \providecommand{\DUfootnotetext}[4]{%
274 \begingroup%
275 \renewcommand{\thefootnote}{%
276 \protect\raisebox{1em}{\protect\hypertarget{#1}{}}%
277 \protect\hyperlink{#2}{#3}}%
278 \footnotetext{#4}%
279 \endgroup%
281 """)) + r"""%
282 \DUfootnotetext{footnote-1}{footnote-1}{1}{%
283 paragraph
286 \DUfootnotetext{footnote-2}{footnote-2}{2}{}
288 \DUfootnotetext{footnote-3}{footnote-3}{3}{
289 \begin{enumerate}
290 \item enumeration
291 \end{enumerate}
294 \end{document}
295 """],
298 totest_latex_toc['no_sectnum'] = [
299 # input
300 ["""\
301 .. contents::
303 first section
304 -------------
305 """,
306 # expected output
307 head_template.substitute(dict(parts,
308 requirements=parts['requirements'] + '\\setcounter{secnumdepth}{0}\n'
309 )) + r"""
310 \phantomsection\label{contents}
311 \pdfbookmark[1]{Contents}{contents}
312 \tableofcontents
315 \section{first section%
316 \label{first-section}%
319 \end{document}
320 """],
323 totest_latex_toc['sectnum'] = [
324 # input
325 ["""\
326 .. contents::
327 .. sectnum::
329 first section
330 -------------
331 """,
332 # expected output
333 head_template.substitute(dict(parts,
334 requirements=parts['requirements'] + '\\setcounter{secnumdepth}{0}\n'
335 )) + r"""
336 \phantomsection\label{contents}
337 \pdfbookmark[1]{Contents}{contents}
338 \tableofcontents
341 \section{1   first section%
342 \label{first-section}%
345 \end{document}
346 """],
349 totest_latex_toc['depth'] = [
350 # input
351 ["""\
352 .. contents::
353 :depth: 1
355 first section
356 -------------
357 """,
358 # expected output
359 head_template.substitute(dict(parts,
360 requirements=parts['requirements'] + '\\setcounter{secnumdepth}{0}\n'
361 )) + r"""
362 \phantomsection\label{contents}
363 \pdfbookmark[1]{Contents}{contents}
364 \setcounter{tocdepth}{1}
365 \tableofcontents
368 \section{first section%
369 \label{first-section}%
372 \end{document}
373 """],
376 totest_latex_toc_book['depth'] = [
377 # input
378 ["""\
379 .. contents::
380 :depth: 1
382 first chapter
383 -------------
384 """,
385 # expected output
386 head_template.substitute(dict(parts,
387 head_prefix=r"""\documentclass[a4paper]{book}
388 """,
389 requirements=parts['requirements'] + '\\setcounter{secnumdepth}{0}\n'
390 )) + r"""
391 \phantomsection\label{contents}
392 \pdfbookmark[1]{Contents}{contents}
393 \setcounter{tocdepth}{0}
394 \tableofcontents
397 \chapter{first chapter%
398 \label{first-chapter}%
401 \end{document}
402 """],
406 totest_latex_sectnum['no_sectnum'] = [
407 # input
408 ["""\
409 some text
411 first section
412 -------------
413 """,
414 # expected output
415 head_template.substitute(dict(parts, requirements = parts['requirements'] +
416 r"""\setcounter{secnumdepth}{0}
417 """)) + r"""
418 some text
421 \section{first section%
422 \label{first-section}%
425 \end{document}
426 """],
429 totest_latex_sectnum['sectnum'] = [
430 # input
431 ["""\
432 .. sectnum::
434 some text
436 first section
437 -------------
438 """,
439 # expected output
440 head_template.substitute(dict(parts,
441 requirements=parts['requirements'] + '\\setcounter{secnumdepth}{0}\n'
442 )) + r"""
443 some text
446 \section{first section%
447 \label{first-section}%
450 \end{document}
451 """],
454 totest_latex_citations['citations_with_underscore'] = [
455 # input
456 ["""\
457 Just a test citation [my_cite2006]_.
459 .. [my_cite2006]
460 The underscore is mishandled.
461 """,
462 # expected output
463 head + r"""
464 Just a test citation \cite{my_cite2006}.
466 \begin{thebibliography}{my\_cite2006}
467 \bibitem[my\_cite2006]{my_cite2006}{
468 The underscore is mishandled.
470 \end{thebibliography}
472 \end{document}
473 """],
477 totest_latex_citations['adjacent_citations'] = [
478 # input
479 ["""\
480 Two non-citations: [MeYou2007]_[YouMe2007]_.
482 Need to be separated for grouping: [MeYou2007]_ [YouMe2007]_.
484 Two spaces (or anything else) for no grouping: [MeYou2007]_ [YouMe2007]_.
486 But a line break should work: [MeYou2007]_
487 [YouMe2007]_.
489 .. [MeYou2007] not.
490 .. [YouMe2007] important.
491 """,
492 # expected output
493 head + r"""
494 Two non-citations: {[}MeYou2007{]}\_{[}YouMe2007{]}\_.
496 Need to be separated for grouping: \cite{MeYou2007,YouMe2007}.
498 Two spaces (or anything else) for no grouping: \cite{MeYou2007} \cite{YouMe2007}.
500 But a line break should work: \cite{MeYou2007,YouMe2007}.
502 \begin{thebibliography}{MeYou2007}
503 \bibitem[MeYou2007]{MeYou2007}{
504 not.
506 \bibitem[YouMe2007]{YouMe2007}{
507 important.
509 \end{thebibliography}
511 \end{document}
512 """],
516 totest['enumerated_lists'] = [
517 # input
518 ["""\
519 1. Item 1.
520 2. Second to the previous item this one will explain
522 a) nothing.
523 b) or some other.
525 3. Third is
527 (I) having pre and postfixes
528 (II) in roman numerals.
529 """,
530 # expected output
531 head + r"""
532 \begin{enumerate}
533 \item Item 1.
535 \item Second to the previous item this one will explain
536 \end{enumerate}
538 \begin{quote}
539 \begin{enumerate}
540 \renewcommand{\labelenumi}{\alph{enumi})}
541 \item nothing.
543 \item or some other.
544 \end{enumerate}
545 \end{quote}
547 \begin{enumerate}
548 \setcounter{enumi}{2}
549 \item Third is
550 \end{enumerate}
552 \begin{quote}
553 \begin{enumerate}
554 \renewcommand{\labelenumi}{(\Roman{enumi})}
555 \item having pre and postfixes
557 \item in roman numerals.
558 \end{enumerate}
559 \end{quote}
561 \end{document}
562 """],
565 # TODO: need to test for quote replacing if the language uses "ASCII-quotes"
566 # as active character (e.g. de (ngerman)).
569 totest['table_caption'] = [
570 # input
571 ["""\
572 .. table:: Foo
574 +-----+-----+
575 | | |
576 +-----+-----+
577 | | |
578 +-----+-----+
579 """,
580 head_table + r"""
581 \setlength{\DUtablewidth}{\linewidth}%
582 \begin{longtable}{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
583 \caption{Foo}\\
584 \hline
585 & \\
586 \hline
587 & \\
588 \hline
589 \end{longtable}
591 \end{document}
592 """],
595 totest['table_styles'] = [
596 ["""\
597 .. table::
598 :class: borderless
600 +-----+-----+
601 | 1 | 2 |
602 +-----+-----+
603 | 3 | 4 |
604 +-----+-----+
605 """,
606 head_table + r"""
607 \setlength{\DUtablewidth}{\linewidth}%
608 \begin{longtable*}{p{0.075\DUtablewidth}p{0.075\DUtablewidth}}
619 \end{longtable*}
621 \end{document}
622 """],
623 ["""\
624 .. table::
625 :class: booktabs
627 +-----+-+
628 | 1 |2|
629 +-----+-+
630 """,
631 head_booktabs + r"""
632 \setlength{\DUtablewidth}{\linewidth}%
633 \begin{longtable*}{p{0.075\DUtablewidth}p{0.028\DUtablewidth}}
634 \toprule
640 \bottomrule
641 \end{longtable*}
643 \end{document}
644 """],
645 ["""\
646 .. table::
647 :class: colwidths-auto
649 +-----+-+
650 | 1 |2|
651 +-----+-+
652 """,
653 head_table + r"""
654 \begin{longtable*}{|l|l|}
655 \hline
656 1 & 2 \\
657 \hline
658 \end{longtable*}
660 \end{document}
661 """],
662 ["""\
663 .. table::
664 :widths: auto
666 +-----+-+
667 | 1 |2|
668 +-----+-+
669 """,
670 head_table + r"""
671 \begin{longtable*}{|l|l|}
672 \hline
673 1 & 2 \\
674 \hline
675 \end{longtable*}
677 \end{document}
678 """],
679 ["""\
680 .. table::
681 :widths: 15, 30
683 +-----+-----+
684 | 1 | 2 |
685 +-----+-----+
686 """,
687 head_table + r"""
688 \setlength{\DUtablewidth}{\linewidth}%
689 \begin{longtable*}{|p{0.191\DUtablewidth}|p{0.365\DUtablewidth}|}
690 \hline
696 \hline
697 \end{longtable*}
699 \end{document}
700 """],
703 totest_table_style_booktabs['table_styles'] = [
704 # borderless overrides "booktabs" table_style
705 ["""\
706 .. table::
707 :class: borderless
709 +-----+-----+
710 | 1 | 2 |
711 +-----+-----+
712 | 3 | 4 |
713 +-----+-----+
714 """,
715 head_table + r"""
716 \setlength{\DUtablewidth}{\linewidth}%
717 \begin{longtable*}{p{0.075\DUtablewidth}p{0.075\DUtablewidth}}
728 \end{longtable*}
730 \end{document}
731 """],
732 ["""\
733 .. table::
734 :widths: auto
736 +-----+-+
737 | 1 |2|
738 +-----+-+
739 """,
740 head_booktabs + r"""
741 \begin{longtable*}{ll}
742 \toprule
743 1 & 2 \\
744 \bottomrule
745 \end{longtable*}
747 \end{document}
748 """],
749 ["""\
750 .. table::
751 :widths: 15, 30
753 +-----+-----+
754 | 1 | 2 |
755 +-----+-----+
756 """,
757 head_booktabs + r"""
758 \setlength{\DUtablewidth}{\linewidth}%
759 \begin{longtable*}{p{0.191\DUtablewidth}p{0.365\DUtablewidth}}
760 \toprule
766 \bottomrule
767 \end{longtable*}
769 \end{document}
770 """],
772 totest_table_style_auto['table_styles'] = [
773 ["""\
774 .. table::
775 :class: borderless
777 +-----+-----+
778 | 1 | 2 |
779 +-----+-----+
780 | 3 | 4 |
781 +-----+-----+
782 """,
783 head_table + r"""
784 \begin{longtable*}{ll}
785 1 & 2 \\
786 3 & 4 \\
787 \end{longtable*}
789 \end{document}
790 """],
791 ["""\
792 .. table::
793 :class: booktabs
795 +-----+-+
796 | 1 |2|
797 +-----+-+
798 """,
799 head_booktabs + r"""
800 \begin{longtable*}{ll}
801 \toprule
802 1 & 2 \\
803 \bottomrule
804 \end{longtable*}
806 \end{document}
807 """],
808 # given width overrides "colwidth-auto"
809 ["""\
810 .. table::
811 :widths: 15, 30
813 +-----+-----+
814 | 1 | 2 |
815 +-----+-----+
816 """,
817 head_table + r"""
818 \setlength{\DUtablewidth}{\linewidth}%
819 \begin{longtable*}{|p{0.191\DUtablewidth}|p{0.365\DUtablewidth}|}
820 \hline
826 \hline
827 \end{longtable*}
829 \end{document}
830 """],
833 totest['table_align'] = [
834 # input
835 ["""\
836 .. table::
837 :align: right
839 +-----+-----+
840 | 1 | 2 |
841 +-----+-----+
842 """,
843 head_table + r"""
844 \setlength{\DUtablewidth}{\linewidth}%
845 \begin{longtable*}[r]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
846 \hline
852 \hline
853 \end{longtable*}
855 \end{document}
856 """],
859 totest['table_empty_cells'] = [
860 ["""\
861 ===== ======
862 Title
863 ===== ======
864 entry value1
865 ===== ======
866 """,
867 head_table + r"""
868 \setlength{\DUtablewidth}{\linewidth}%
869 \begin{longtable*}{|p{0.075\DUtablewidth}|p{0.086\DUtablewidth}|}
870 \hline
871 \textbf{%
872 Title
873 } & \\
874 \hline
875 \endfirsthead
876 \hline
877 \textbf{%
878 Title
879 } & \\
880 \hline
881 \endhead
882 \multicolumn{2}{p{0.16\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
883 \endfoot
884 \endlastfoot
886 entry
888 value1
890 \hline
891 \end{longtable*}
893 \end{document}
894 """],
895 ["""\
896 +----+----+
897 | c3 | c4 |
898 +----+----+
900 +---------+
901 """,
902 head_table + r"""
903 \setlength{\DUtablewidth}{\linewidth}%
904 \begin{longtable*}{|p{0.063\DUtablewidth}|p{0.063\DUtablewidth}|}
905 \hline
911 \hline
912 \multicolumn{2}{|p{0.13\DUtablewidth}|}{} \\
913 \hline
914 \end{longtable*}
916 \end{document}
917 """],
920 totest['table_nonstandard_class'] = [
921 ["""\
922 .. table::
923 :class: my-class
925 +-----+-----+
926 | 1 | 2 |
927 +-----+-----+
928 | 3 | 4 |
929 +-----+-----+
930 """,
931 head_template.substitute(
932 dict(
933 parts,
934 requirements = parts['requirements'] + parts['longtable'],
935 fallbacks = r"""
936 % class handling for environments (block-level elements)
937 % \begin{DUclass}{spam} tries \DUCLASSspam and
938 % \end{DUclass}{spam} tries \endDUCLASSspam
939 \ifx\DUclass\undefined % poor man's "provideenvironment"
940 \newenvironment{DUclass}[1]%
941 {% "#1" does not work in end-part of environment.
942 \def\DocutilsClassFunctionName{DUCLASS#1}
943 \csname \DocutilsClassFunctionName \endcsname}%
944 {\csname end\DocutilsClassFunctionName \endcsname}%
948 ) + r"""
949 \begin{DUclass}{my-class}
950 \setlength{\DUtablewidth}{\linewidth}%
951 \begin{longtable*}{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
952 \hline
958 \hline
964 \hline
965 \end{longtable*}
966 \end{DUclass}
968 \end{document}
969 """],
972 # The "[" needs to be protected (otherwise it will be seen as an
973 # option to "\\", "\item", etc. ).
975 totest['bracket_protection'] = [
976 # input
977 ["""
978 * [no option] to this item
979 """,
980 head + r"""
981 \begin{itemize}
982 \item {[}no option{]} to this item
983 \end{itemize}
985 \end{document}
986 """],
989 totest['literal_block'] = [
990 # input
991 ["""\
992 Test special characters { [ \\\\ ] } in literal block::
994 { [ ( \\macro
996 } ] )
997 """,
998 head_alltt + r"""
999 Test special characters \{ {[} \textbackslash{} {]} \} in literal block:
1001 \begin{quote}
1002 \begin{alltt}
1003 \{ [ ( \textbackslash{}macro
1005 \} ] )
1006 \end{alltt}
1007 \end{quote}
1009 \end{document}
1010 """],
1013 totest['raw'] = [
1014 [r""".. raw:: latex
1016 $E=mc^2$
1018 A paragraph.
1020 .. |sub| raw:: latex
1022 (some raw text)
1024 Foo |sub|
1025 same paragraph.
1026 """,
1027 head + r"""
1028 $E=mc^2$
1030 A paragraph.
1032 Foo (some raw text)
1033 same paragraph.
1035 \end{document}
1036 """],
1037 [r""".. compound::
1039 Compound paragraph
1041 .. raw:: LaTeX
1043 raw LaTeX block
1045 compound paragraph continuation.
1046 """,
1047 head_template.substitute(
1048 dict(parts,
1049 fallbacks = r"""
1050 % class handling for environments (block-level elements)
1051 % \begin{DUclass}{spam} tries \DUCLASSspam and
1052 % \end{DUclass}{spam} tries \endDUCLASSspam
1053 \ifx\DUclass\undefined % poor man's "provideenvironment"
1054 \newenvironment{DUclass}[1]%
1055 {% "#1" does not work in end-part of environment.
1056 \def\DocutilsClassFunctionName{DUCLASS#1}
1057 \csname \DocutilsClassFunctionName \endcsname}%
1058 {\csname end\DocutilsClassFunctionName \endcsname}%
1062 ) + r"""
1063 \begin{DUclass}{compound}
1064 Compound paragraph
1065 raw LaTeX block
1066 compound paragraph continuation.
1067 \end{DUclass}
1069 \end{document}
1070 """],
1073 totest['title_with_inline_markup'] = [
1074 ["""\
1075 This is the *Title*
1076 ===================
1078 This is the *Subtitle*
1079 ----------------------
1081 This is a *section title*
1082 ~~~~~~~~~~~~~~~~~~~~~~~~~
1084 This is the *document*.
1085 """,
1086 head_template.substitute(dict(parts,
1087 requirements=parts['requirements'] + '\\setcounter{secnumdepth}{0}\n',
1088 fallbacks=r"""
1089 % subtitle (in document title)
1090 \providecommand*{\DUdocumentsubtitle}[1]{{\large #1}}
1091 """,
1092 pdfsetup=parts['pdfsetup'] + r"""\hypersetup{
1093 pdftitle={This is the Title},
1095 """, titledata=r"""\title{This is the \emph{Title}%
1096 \label{this-is-the-title}%
1098 \DUdocumentsubtitle{This is the \emph{Subtitle}}%
1099 \label{this-is-the-subtitle}}
1100 \author{}
1101 \date{}
1102 """)) + r"""\maketitle
1105 \section{This is a \emph{section title}%
1106 \label{this-is-a-section-title}%
1109 This is the \emph{document}.
1111 \end{document}
1112 """],
1115 totest_stylesheet['two-styles'] = [
1116 # input
1117 ["""two stylesheet links in the header""",
1118 head_template.substitute(dict(parts, stylesheet =
1119 r"""\usepackage{data/spam}
1120 \input{data/ham.tex}
1121 """)) + r"""
1122 two stylesheet links in the header
1124 \end{document}
1125 """],
1128 totest_stylesheet_embed['two-styles'] = [
1129 # input
1130 ["""two stylesheets embedded in the header""",
1131 head_template.substitute(dict(parts, stylesheet =
1132 r"""% Cannot embed stylesheet 'data/spam.sty':
1133 % No such file or directory.
1134 % embedded stylesheet: data/ham.tex
1135 \newcommand{\ham}{wonderful ham}
1137 """)) + r"""
1138 two stylesheets embedded in the header
1140 \end{document}
1141 """],
1144 if __name__ == '__main__':
1145 import unittest
1146 unittest.main(defaultTest='suite')