| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
Tests for latex2e writer. |
| 9 |
|
| 10 |
This module tests only the "body" part of the output. |
| 11 |
For tests of constructs that change the "head", see test-latex2e_parts.py. |
| 12 |
""" |
| 13 |
|
| 14 |
from pathlib import Path |
| 15 |
import sys |
| 16 |
import unittest |
| 17 |
|
| 18 |
if __name__ == '__main__': |
| 19 |
|
| 20 |
|
| 21 |
sys.path.insert(0, str(Path(__file__).resolve().parents[2])) |
| 22 |
|
| 23 |
from docutils.core import publish_parts |
| 24 |
from docutils.writers import latex2e |
| 25 |
|
| 26 |
|
| 27 |
class WriterPublishTestCase(unittest.TestCase): |
| 28 |
|
| 29 |
maxDiff = None |
| 30 |
settings = { |
| 31 |
'_disable_config': True, |
| 32 |
'strict_visitor': True, |
| 33 |
|
| 34 |
'use_latex_citations': False, |
| 35 |
'legacy_column_widths': True, |
| 36 |
} |
| 37 |
|
| 38 |
def test_body(self): |
| 39 |
for name, (settings_overrides, cases) in samples.items(): |
| 40 |
for casenum, (rst_input, expected) in enumerate(cases): |
| 41 |
with self.subTest(id=f'samples[{name!r}][{casenum}]'): |
| 42 |
output = publish_parts( |
| 43 |
source=rst_input, |
| 44 |
writer=latex2e.Writer(), |
| 45 |
settings_overrides=self.settings|settings_overrides |
| 46 |
)['body'] |
| 47 |
self.assertEqual(expected, output) |
| 48 |
|
| 49 |
|
| 50 |
samples = {} |
| 51 |
|
| 52 |
|
| 53 |
samples['default'] = ({}, [ |
| 54 |
|
| 55 |
['http://nowhere/url_with%28parens%29', |
| 56 |
'\n\\url{http://nowhere/url_with\\%28parens\\%29}\n' |
| 57 |
], |
| 58 |
|
| 59 |
["""\ |
| 60 |
1. Item 1. |
| 61 |
2. Second to the previous item this one will explain |
| 62 |
|
| 63 |
a) nothing. |
| 64 |
b) or some other. |
| 65 |
|
| 66 |
3. Third is |
| 67 |
|
| 68 |
(I) having pre and postfixes |
| 69 |
(II) in roman numerals. |
| 70 |
""", |
| 71 |
r""" |
| 72 |
\begin{enumerate} |
| 73 |
\item Item 1. |
| 74 |
|
| 75 |
\item Second to the previous item this one will explain |
| 76 |
\end{enumerate} |
| 77 |
|
| 78 |
\begin{quote} |
| 79 |
\begin{enumerate} |
| 80 |
\renewcommand{\labelenumi}{\alph{enumi})} |
| 81 |
\item nothing. |
| 82 |
|
| 83 |
\item or some other. |
| 84 |
\end{enumerate} |
| 85 |
\end{quote} |
| 86 |
|
| 87 |
\begin{enumerate} |
| 88 |
\setcounter{enumi}{2} |
| 89 |
\item Third is |
| 90 |
\end{enumerate} |
| 91 |
|
| 92 |
\begin{quote} |
| 93 |
\begin{enumerate} |
| 94 |
\renewcommand{\labelenumi}{(\Roman{enumi})} |
| 95 |
\item having pre and postfixes |
| 96 |
|
| 97 |
\item in roman numerals. |
| 98 |
\end{enumerate} |
| 99 |
\end{quote} |
| 100 |
"""], |
| 101 |
|
| 102 |
[""" |
| 103 |
* [no option] to this item |
| 104 |
""", |
| 105 |
r""" |
| 106 |
\begin{itemize} |
| 107 |
\item {[}no option{]} to this item |
| 108 |
\end{itemize} |
| 109 |
"""], |
| 110 |
|
| 111 |
[r""".. raw:: latex |
| 112 |
|
| 113 |
$E=mc^2$ |
| 114 |
|
| 115 |
A paragraph. |
| 116 |
|
| 117 |
.. |sub| raw:: latex |
| 118 |
|
| 119 |
(some raw text) |
| 120 |
|
| 121 |
Foo |sub| |
| 122 |
same paragraph. |
| 123 |
""", |
| 124 |
r""" |
| 125 |
$E=mc^2$ |
| 126 |
|
| 127 |
A paragraph. |
| 128 |
|
| 129 |
Foo (some raw text) |
| 130 |
same paragraph. |
| 131 |
"""], |
| 132 |
|
| 133 |
["""\ |
| 134 |
.. figure:: parrot.png |
| 135 |
:figclass: figureclass |
| 136 |
:figname: fig-ure |
| 137 |
|
| 138 |
.. class:: f-caption-class |
| 139 |
.. _f-caption: |
| 140 |
|
| 141 |
A figure with caption |
| 142 |
|
| 143 |
.. class:: legend-class |
| 144 |
.. _le-gend: |
| 145 |
|
| 146 |
A figure legend |
| 147 |
|
| 148 |
.. image:: parrot.png |
| 149 |
:class: imgclass TODO ignored! |
| 150 |
:name: i-mage |
| 151 |
:target: example.org/parrots |
| 152 |
|
| 153 |
See i-mage_ and fig-ure_ with f-caption_ and le-gend_. |
| 154 |
""", |
| 155 |
r""" |
| 156 |
\phantomsection\label{fig-ure} |
| 157 |
\begin{DUclass}{figureclass} |
| 158 |
\begin{figure} |
| 159 |
\noindent\makebox[\linewidth][c]{\includegraphics{parrot.png}} |
| 160 |
\caption{\label{f-caption}\DUrole{f-caption-class}{A figure with caption}} |
| 161 |
\begin{DUlegend} |
| 162 |
\phantomsection\label{le-gend} |
| 163 |
\DUrole{legend-class}{A figure legend} |
| 164 |
\end{DUlegend} |
| 165 |
\end{figure} |
| 166 |
\end{DUclass} |
| 167 |
|
| 168 |
\phantomsection\label{i-mage} |
| 169 |
\href{example.org/parrots}{\includegraphics{parrot.png}} |
| 170 |
|
| 171 |
See \hyperref[i-mage]{i-mage} and \hyperref[fig-ure]{fig-ure} with \hyperref[f-caption]{f-caption} and \hyperref[le-gend]{le-gend}. |
| 172 |
"""], |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
["""\ |
| 177 |
.. table:: |
| 178 |
:class: borderless |
| 179 |
|
| 180 |
+-----+-----+ |
| 181 |
| 1 | 2 | |
| 182 |
+-----+-----+ |
| 183 |
| 3 | 4 | |
| 184 |
+-----+-----+ |
| 185 |
""", |
| 186 |
""" |
| 187 |
\\setlength{\\DUtablewidth}{\\linewidth}% |
| 188 |
\\begin{longtable*}{p{0.075\\DUtablewidth}p{0.075\\DUtablewidth}} |
| 189 |
|
| 190 |
1 |
| 191 |
& \n\ |
| 192 |
2 |
| 193 |
\\\\ |
| 194 |
|
| 195 |
3 |
| 196 |
& \n\ |
| 197 |
4 |
| 198 |
\\\\ |
| 199 |
\\end{longtable*} |
| 200 |
"""], |
| 201 |
|
| 202 |
["""\ |
| 203 |
.. table:: |
| 204 |
:class: colwidths-auto |
| 205 |
|
| 206 |
+-----+-+ |
| 207 |
| 1 |2| |
| 208 |
+-----+-+ |
| 209 |
""", |
| 210 |
r""" |
| 211 |
\begin{longtable*}{|l|l|} |
| 212 |
\hline |
| 213 |
1 & 2 \\ |
| 214 |
\hline |
| 215 |
\end{longtable*} |
| 216 |
"""], |
| 217 |
|
| 218 |
["""\ |
| 219 |
.. table:: |
| 220 |
:widths: auto |
| 221 |
|
| 222 |
+-----+-+ |
| 223 |
| 1 |2| |
| 224 |
+-----+-+ |
| 225 |
""", |
| 226 |
r""" |
| 227 |
\begin{longtable*}{|l|l|} |
| 228 |
\hline |
| 229 |
1 & 2 \\ |
| 230 |
\hline |
| 231 |
\end{longtable*} |
| 232 |
"""], |
| 233 |
|
| 234 |
["""\ |
| 235 |
.. table:: |
| 236 |
:widths: 15, 30 |
| 237 |
|
| 238 |
+-----+-----+ |
| 239 |
| 1 | 2 | |
| 240 |
+-----+-----+ |
| 241 |
""", |
| 242 |
""" |
| 243 |
\\setlength{\\DUtablewidth}{\\linewidth}% |
| 244 |
\\begin{longtable*}{|p{0.191\\DUtablewidth}|p{0.365\\DUtablewidth}|} |
| 245 |
\\hline |
| 246 |
|
| 247 |
1 |
| 248 |
& \n\ |
| 249 |
2 |
| 250 |
\\\\ |
| 251 |
\\hline |
| 252 |
\\end{longtable*} |
| 253 |
"""], |
| 254 |
|
| 255 |
["""\ |
| 256 |
.. table:: |
| 257 |
:align: right |
| 258 |
|
| 259 |
+-----+-----+ |
| 260 |
| 1 | 2 | |
| 261 |
+-----+-----+ |
| 262 |
""", |
| 263 |
""" |
| 264 |
\\setlength{\\DUtablewidth}{\\linewidth}% |
| 265 |
\\begin{longtable*}[r]{|p{0.075\\DUtablewidth}|p{0.075\\DUtablewidth}|} |
| 266 |
\\hline |
| 267 |
|
| 268 |
1 |
| 269 |
& \n\ |
| 270 |
2 |
| 271 |
\\\\ |
| 272 |
\\hline |
| 273 |
\\end{longtable*} |
| 274 |
"""], |
| 275 |
|
| 276 |
["""\ |
| 277 |
===== ====== |
| 278 |
Title |
| 279 |
===== ====== |
| 280 |
entry value1 |
| 281 |
===== ====== |
| 282 |
""", |
| 283 |
""" |
| 284 |
\\setlength{\\DUtablewidth}{\\linewidth}% |
| 285 |
\\begin{longtable*}{|p{0.075\\DUtablewidth}|p{0.086\\DUtablewidth}|} |
| 286 |
\\hline |
| 287 |
\\textbf{% |
| 288 |
Title |
| 289 |
} & \\\\ |
| 290 |
\\hline |
| 291 |
\\endfirsthead |
| 292 |
\\hline |
| 293 |
\\textbf{% |
| 294 |
Title |
| 295 |
} & \\\\ |
| 296 |
\\hline |
| 297 |
\\endhead |
| 298 |
\\multicolumn{2}{p{0.16\\DUtablewidth}}{\\raggedleft\\ldots continued on next page}\\\\ |
| 299 |
\\endfoot |
| 300 |
\\endlastfoot |
| 301 |
|
| 302 |
entry |
| 303 |
& \n\ |
| 304 |
value1 |
| 305 |
\\\\ |
| 306 |
\\hline |
| 307 |
\\end{longtable*} |
| 308 |
"""], |
| 309 |
|
| 310 |
["""\ |
| 311 |
+----+----+ |
| 312 |
| c3 | c4 | |
| 313 |
+----+----+ |
| 314 |
| | |
| 315 |
+---------+ |
| 316 |
""", |
| 317 |
""" |
| 318 |
\\setlength{\\DUtablewidth}{\\linewidth}% |
| 319 |
\\begin{longtable*}{|p{0.063\\DUtablewidth}|p{0.063\\DUtablewidth}|} |
| 320 |
\\hline |
| 321 |
|
| 322 |
c3 |
| 323 |
& \n\ |
| 324 |
c4 |
| 325 |
\\\\ |
| 326 |
\\hline |
| 327 |
\\multicolumn{2}{|p{0.13\\DUtablewidth}|}{} \\\\ |
| 328 |
\\hline |
| 329 |
\\end{longtable*} |
| 330 |
"""], |
| 331 |
]) |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
samples['IDs and classes'] = ({}, [ |
| 336 |
["""\ |
| 337 |
A paragraph with _`inline target`. |
| 338 |
|
| 339 |
.. _block target: |
| 340 |
|
| 341 |
.. class:: custom paragraph |
| 342 |
|
| 343 |
Links to `block target`_ and `inline target`_. |
| 344 |
""", |
| 345 |
r""" |
| 346 |
A paragraph with % |
| 347 |
\phantomsection\label{inline-target}inline target. |
| 348 |
|
| 349 |
\phantomsection\label{block-target} |
| 350 |
\DUrole{custom}{\DUrole{paragraph}{Links to \hyperref[block-target]{block target} and \hyperref[inline-target]{inline target}.}} |
| 351 |
"""], |
| 352 |
|
| 353 |
[""" |
| 354 |
.. class:: cls1 |
| 355 |
.. _label1: |
| 356 |
|
| 357 |
Exlicit is better than implicit. |
| 358 |
|
| 359 |
.. class:: attribute-cls cute |
| 360 |
.. _an attribution: |
| 361 |
|
| 362 |
-- Zen of Python |
| 363 |
|
| 364 |
See quote label1_ with `an attribution`_. |
| 365 |
""", |
| 366 |
r""" |
| 367 |
\phantomsection\label{label1} |
| 368 |
\begin{DUclass}{cls1} |
| 369 |
\begin{quote} |
| 370 |
Exlicit is better than implicit. |
| 371 |
\nopagebreak |
| 372 |
|
| 373 |
\phantomsection\label{an-attribution} |
| 374 |
\begin{DUclass}{attribute-cls} |
| 375 |
\begin{DUclass}{cute} |
| 376 |
\raggedleft —Zen of Python |
| 377 |
\end{DUclass} |
| 378 |
\end{DUclass} |
| 379 |
\end{quote} |
| 380 |
\end{DUclass} |
| 381 |
|
| 382 |
See quote \hyperref[label1]{label1} with \hyperref[an-attribution]{an attribution}. |
| 383 |
"""], |
| 384 |
|
| 385 |
[""" |
| 386 |
.. class:: cls1 |
| 387 |
.. _bullet1: |
| 388 |
|
| 389 |
* list item |
| 390 |
|
| 391 |
.. class:: bullet-class |
| 392 |
.. _b-item: |
| 393 |
|
| 394 |
* second bullet list item |
| 395 |
|
| 396 |
.. class:: def-list-class |
| 397 |
.. _def-list: |
| 398 |
|
| 399 |
definition |
| 400 |
list |
| 401 |
|
| 402 |
.. class:: def-item-class |
| 403 |
.. _def-item: |
| 404 |
|
| 405 |
term |
| 406 |
definition |
| 407 |
|
| 408 |
.. class:: cls1 |
| 409 |
.. _enumerated1: |
| 410 |
|
| 411 |
#. list item |
| 412 |
|
| 413 |
.. class:: e-item-class |
| 414 |
.. _e-item: |
| 415 |
|
| 416 |
#. enumerated list item |
| 417 |
|
| 418 |
.. class:: fieldlist-class |
| 419 |
.. _f-list: |
| 420 |
|
| 421 |
:field: list |
| 422 |
|
| 423 |
.. class:: field-class |
| 424 |
.. _f-list-item: |
| 425 |
|
| 426 |
:name: body |
| 427 |
|
| 428 |
.. class:: o-list-class |
| 429 |
.. _o-list: |
| 430 |
|
| 431 |
--an option list |
| 432 |
|
| 433 |
.. class:: option-class |
| 434 |
.. _o-item: |
| 435 |
|
| 436 |
--another option |
| 437 |
|
| 438 |
See bullet1_, b-item_, |
| 439 |
def-list_, def-item_, |
| 440 |
enumerated1_, e-item_, |
| 441 |
f-list_, f-list-item_, |
| 442 |
o-list_, and o-item_. |
| 443 |
""", |
| 444 |
""" |
| 445 |
\\phantomsection\\label{bullet1} |
| 446 |
\\begin{DUclass}{cls1} |
| 447 |
\\begin{itemize} |
| 448 |
\\item list item |
| 449 |
|
| 450 |
\\phantomsection\\label{b-item} |
| 451 |
\\item second bullet list item |
| 452 |
\\end{itemize} |
| 453 |
\\end{DUclass} |
| 454 |
|
| 455 |
\\phantomsection\\label{def-list} |
| 456 |
\\begin{DUclass}{def-list-class} |
| 457 |
\\begin{description} |
| 458 |
\\item[{definition}] \n\ |
| 459 |
list |
| 460 |
|
| 461 |
\\phantomsection\\label{def-item} |
| 462 |
\\item[{term}] \n\ |
| 463 |
definition |
| 464 |
\\end{description} |
| 465 |
\\end{DUclass} |
| 466 |
|
| 467 |
\\phantomsection\\label{enumerated1} |
| 468 |
\\begin{DUclass}{cls1} |
| 469 |
\\begin{enumerate} |
| 470 |
\\item list item |
| 471 |
|
| 472 |
\\phantomsection\\label{e-item} |
| 473 |
\\item enumerated list item |
| 474 |
\\end{enumerate} |
| 475 |
\\end{DUclass} |
| 476 |
|
| 477 |
\\phantomsection\\label{f-list} |
| 478 |
\\begin{DUclass}{fieldlist-class} |
| 479 |
\\begin{DUfieldlist} |
| 480 |
\\item[{field:}] |
| 481 |
list |
| 482 |
|
| 483 |
\\phantomsection\\label{f-list-item} |
| 484 |
\\item[{name:}] |
| 485 |
body |
| 486 |
\\end{DUfieldlist} |
| 487 |
\\end{DUclass} |
| 488 |
|
| 489 |
\\phantomsection\\label{o-list} |
| 490 |
\\begin{DUclass}{o-list-class} |
| 491 |
\\begin{DUoptionlist} |
| 492 |
\\item[-{}-an] option list |
| 493 |
\\phantomsection\\label{o-item} |
| 494 |
\\item[-{}-another] option |
| 495 |
\\end{DUoptionlist} |
| 496 |
\\end{DUclass} |
| 497 |
|
| 498 |
See \\hyperref[bullet1]{bullet1}, \\hyperref[b-item]{b-item}, |
| 499 |
\\hyperref[def-list]{def-list}, \\hyperref[def-item]{def-item}, |
| 500 |
\\hyperref[enumerated1]{enumerated1}, \\hyperref[e-item]{e-item}, |
| 501 |
\\hyperref[f-list]{f-list}, \\hyperref[f-list-item]{f-list-item}, |
| 502 |
\\hyperref[o-list]{o-list}, and \\hyperref[o-item]{o-item}. |
| 503 |
"""], |
| 504 |
|
| 505 |
["""\ |
| 506 |
.. class:: lineblock-class |
| 507 |
.. _line-block: |
| 508 |
|
| 509 |
| line block |
| 510 |
| second line |
| 511 |
|
| 512 |
.. class:: cls1 |
| 513 |
.. _block1: |
| 514 |
|
| 515 |
:: |
| 516 |
|
| 517 |
1^2_3 |
| 518 |
|
| 519 |
See line-block_ and block1_. |
| 520 |
""", |
| 521 |
r""" |
| 522 |
\phantomsection\label{line-block} |
| 523 |
\begin{DUclass}{lineblock-class} |
| 524 |
\begin{DUlineblock}{0em} |
| 525 |
\item[] line block |
| 526 |
\item[] second line |
| 527 |
\end{DUlineblock} |
| 528 |
\end{DUclass} |
| 529 |
|
| 530 |
\phantomsection\label{block1} |
| 531 |
\begin{DUclass}{cls1} |
| 532 |
\begin{quote} |
| 533 |
\begin{alltt} |
| 534 |
1^2_3 |
| 535 |
\end{alltt} |
| 536 |
\end{quote} |
| 537 |
\end{DUclass} |
| 538 |
|
| 539 |
See \hyperref[line-block]{line-block} and \hyperref[block1]{block1}. |
| 540 |
"""], |
| 541 |
|
| 542 |
["""\ |
| 543 |
.. class:: cls1 |
| 544 |
.. _label1: |
| 545 |
.. table:: |
| 546 |
:name: label2 |
| 547 |
:class: cls2 borderless |
| 548 |
:widths: auto |
| 549 |
|
| 550 |
= = |
| 551 |
Y N |
| 552 |
= = |
| 553 |
|
| 554 |
Refer to the table with either label1_ or label2_. |
| 555 |
""", |
| 556 |
r""" |
| 557 |
\phantomsection\label{label2}\label{label1} |
| 558 |
\begin{DUclass}{cls2} |
| 559 |
\begin{DUclass}{cls1} |
| 560 |
\begin{longtable*}{ll} |
| 561 |
Y & N \\ |
| 562 |
\end{longtable*} |
| 563 |
\end{DUclass} |
| 564 |
\end{DUclass} |
| 565 |
|
| 566 |
Refer to the table with either \hyperref[label1]{label1} or \hyperref[label2]{label2}. |
| 567 |
"""], |
| 568 |
|
| 569 |
["""\ |
| 570 |
.. compound:: |
| 571 |
:class: compoundclass |
| 572 |
:name: com-pound |
| 573 |
|
| 574 |
Compound paragraph 1 |
| 575 |
|
| 576 |
Compound paragraph 2 |
| 577 |
|
| 578 |
.. container:: containerclass |
| 579 |
:name: con-tainer |
| 580 |
|
| 581 |
Container paragraph 1 |
| 582 |
|
| 583 |
Container paragraph 2 |
| 584 |
|
| 585 |
.. class:: cls1 |
| 586 |
.. _label1: |
| 587 |
.. hint:: |
| 588 |
:name: label2 |
| 589 |
:class: cls2 |
| 590 |
|
| 591 |
Don't forget to breathe. |
| 592 |
|
| 593 |
.. math:: x = 2^4 |
| 594 |
:class: mathclass |
| 595 |
:name: math-block |
| 596 |
|
| 597 |
.. _my-raw: |
| 598 |
.. raw:: latex pseudoxml xml |
| 599 |
:class: rawclass |
| 600 |
|
| 601 |
\\LaTeX |
| 602 |
|
| 603 |
.. sidebar:: sidebar title |
| 604 |
:class: sideclass |
| 605 |
:name: side-bar |
| 606 |
|
| 607 |
sidebar content |
| 608 |
|
| 609 |
.. topic:: topic heading |
| 610 |
:class: topicclass |
| 611 |
:name: to-pic |
| 612 |
|
| 613 |
topic content |
| 614 |
|
| 615 |
See hint with label1_ and label2_, |
| 616 |
com-pound_, con-tainer_, |
| 617 |
math-block_, my-raw_, |
| 618 |
side-bar_, and to-pic_. |
| 619 |
""", |
| 620 |
r""" |
| 621 |
\phantomsection\label{com-pound} |
| 622 |
\begin{DUclass}{compound} |
| 623 |
\begin{DUclass}{compoundclass} |
| 624 |
Compound paragraph 1 |
| 625 |
|
| 626 |
Compound paragraph 2 |
| 627 |
\end{DUclass} |
| 628 |
\end{DUclass} |
| 629 |
|
| 630 |
\phantomsection\label{con-tainer} |
| 631 |
\begin{DUclass}{containerclass} |
| 632 |
Container paragraph 1 |
| 633 |
|
| 634 |
Container paragraph 2 |
| 635 |
\end{DUclass} |
| 636 |
|
| 637 |
\phantomsection\label{label2}\label{label1} |
| 638 |
\begin{DUclass}{cls2} |
| 639 |
\begin{DUclass}{cls1} |
| 640 |
\begin{DUclass}{hint} |
| 641 |
\begin{DUadmonition} |
| 642 |
\DUtitle{Hint} |
| 643 |
|
| 644 |
Don't forget to breathe. |
| 645 |
\end{DUadmonition} |
| 646 |
\end{DUclass} |
| 647 |
\end{DUclass} |
| 648 |
\end{DUclass} |
| 649 |
% |
| 650 |
\phantomsection |
| 651 |
\DUrole{mathclass}{% |
| 652 |
\begin{equation*} |
| 653 |
x = 2^4 |
| 654 |
\label{math-block} |
| 655 |
\end{equation*} |
| 656 |
} |
| 657 |
\phantomsection\label{my-raw}\DUrole{rawclass}{\LaTeX} |
| 658 |
|
| 659 |
\phantomsection\label{side-bar} |
| 660 |
\begin{DUclass}{sideclass} |
| 661 |
\DUsidebar{ |
| 662 |
\DUtitle{sidebar title} |
| 663 |
|
| 664 |
sidebar content |
| 665 |
} |
| 666 |
\end{DUclass} |
| 667 |
|
| 668 |
\phantomsection\label{to-pic} |
| 669 |
\begin{DUclass}{topic} |
| 670 |
\begin{DUclass}{topicclass} |
| 671 |
\begin{quote} |
| 672 |
\DUtitle{topic heading} |
| 673 |
|
| 674 |
topic content |
| 675 |
\end{quote} |
| 676 |
\end{DUclass} |
| 677 |
\end{DUclass} |
| 678 |
|
| 679 |
See hint with \hyperref[label1]{label1} and \hyperref[label2]{label2}, |
| 680 |
\hyperref[com-pound]{com-pound}, \hyperref[con-tainer]{con-tainer}, |
| 681 |
\hyperref[math-block]{math-block}, \hyperref[my-raw]{my-raw}, |
| 682 |
\hyperref[side-bar]{side-bar}, and \hyperref[to-pic]{to-pic}. |
| 683 |
"""], |
| 684 |
]) |
| 685 |
|
| 686 |
samples['latex_sectnum'] = ({'sectnum_xform': False}, [ |
| 687 |
["""\ |
| 688 |
.. sectnum:: |
| 689 |
|
| 690 |
some text |
| 691 |
|
| 692 |
first section |
| 693 |
------------- |
| 694 |
""", |
| 695 |
r""" |
| 696 |
some text |
| 697 |
|
| 698 |
|
| 699 |
\section{first section} |
| 700 |
"""], |
| 701 |
]) |
| 702 |
|
| 703 |
|
| 704 |
samples['latex_citations'] = ({'use_latex_citations': True}, [ |
| 705 |
["""\ |
| 706 |
Just a test citation [my_cite2006]_. |
| 707 |
|
| 708 |
.. [my_cite2006] |
| 709 |
Watch the underscore! |
| 710 |
""", |
| 711 |
r""" |
| 712 |
Just a test citation \cite{my_cite2006}. |
| 713 |
|
| 714 |
\begin{thebibliography}{my\_cite2006} |
| 715 |
\bibitem[my\_cite2006]{my_cite2006}{ |
| 716 |
Watch the underscore! |
| 717 |
} |
| 718 |
\end{thebibliography} |
| 719 |
"""], |
| 720 |
["""\ |
| 721 |
Two non-citations: [MeYou2007]_[YouMe2007]_. |
| 722 |
|
| 723 |
Need to be separated for grouping: [MeYou2007]_ [YouMe2007]_. |
| 724 |
|
| 725 |
Two spaces (or anything else) for no grouping: [MeYou2007]_ [YouMe2007]_. |
| 726 |
|
| 727 |
But a line break should work: [MeYou2007]_ |
| 728 |
[YouMe2007]_. |
| 729 |
|
| 730 |
.. [MeYou2007] not. |
| 731 |
.. [YouMe2007] important. |
| 732 |
""", |
| 733 |
r""" |
| 734 |
Two non-citations: {[}MeYou2007{]}\_{[}YouMe2007{]}\_. |
| 735 |
|
| 736 |
Need to be separated for grouping: \cite{MeYou2007,YouMe2007}. |
| 737 |
|
| 738 |
Two spaces (or anything else) for no grouping: \cite{MeYou2007} \cite{YouMe2007}. |
| 739 |
|
| 740 |
But a line break should work: \cite{MeYou2007,YouMe2007}. |
| 741 |
|
| 742 |
\begin{thebibliography}{MeYou2007} |
| 743 |
\bibitem[MeYou2007]{MeYou2007}{ |
| 744 |
not. |
| 745 |
} |
| 746 |
\bibitem[YouMe2007]{YouMe2007}{ |
| 747 |
important. |
| 748 |
} |
| 749 |
\end{thebibliography} |
| 750 |
"""], |
| 751 |
]) |
| 752 |
|
| 753 |
|
| 754 |
samples['colwidths_auto'] = ({'table_style': ['colwidths-auto']}, [ |
| 755 |
|
| 756 |
|
| 757 |
["""\ |
| 758 |
.. table:: |
| 759 |
:class: borderless |
| 760 |
|
| 761 |
+-----+-----+ |
| 762 |
| 1 | 2 | |
| 763 |
+-----+-----+ |
| 764 |
| 3 | 4 | |
| 765 |
+-----+-----+ |
| 766 |
""", |
| 767 |
r""" |
| 768 |
\begin{longtable*}{ll} |
| 769 |
1 & 2 \\ |
| 770 |
3 & 4 \\ |
| 771 |
\end{longtable*} |
| 772 |
"""], |
| 773 |
|
| 774 |
["""\ |
| 775 |
.. table:: |
| 776 |
:class: booktabs |
| 777 |
|
| 778 |
+-----+-+ |
| 779 |
| 1 |2| |
| 780 |
+-----+-+ |
| 781 |
""", |
| 782 |
r""" |
| 783 |
\begin{longtable*}{ll} |
| 784 |
\toprule |
| 785 |
1 & 2 \\ |
| 786 |
\bottomrule |
| 787 |
\end{longtable*} |
| 788 |
"""], |
| 789 |
|
| 790 |
["""\ |
| 791 |
.. table:: |
| 792 |
:widths: 15, 30 |
| 793 |
|
| 794 |
+-----+-----+ |
| 795 |
| 1 | 2 | |
| 796 |
+-----+-----+ |
| 797 |
""", |
| 798 |
""" |
| 799 |
\\setlength{\\DUtablewidth}{\\linewidth}% |
| 800 |
\\begin{longtable*}{|p{0.191\\DUtablewidth}|p{0.365\\DUtablewidth}|} |
| 801 |
\\hline |
| 802 |
|
| 803 |
1 |
| 804 |
& \n\ |
| 805 |
2 |
| 806 |
\\\\ |
| 807 |
\\hline |
| 808 |
\\end{longtable*} |
| 809 |
"""], |
| 810 |
]) |
| 811 |
|
| 812 |
|
| 813 |
samples['bibtex'] = ({'use_bibtex': ['alpha', 'xampl']}, [ |
| 814 |
["""\ |
| 815 |
Just a test citation [book-full]_. |
| 816 |
""", |
| 817 |
r""" |
| 818 |
Just a test citation \cite{book-full}. |
| 819 |
|
| 820 |
\bibliographystyle{alpha} |
| 821 |
\bibliography{xampl} |
| 822 |
"""], |
| 823 |
["""\ |
| 824 |
No bibliography if there is no citation. |
| 825 |
""", |
| 826 |
r""" |
| 827 |
No bibliography if there is no citation. |
| 828 |
"""], |
| 829 |
]) |
| 830 |
|
| 831 |
samples['docutils-footnotes'] = ({}, [ |
| 832 |
|
| 833 |
[r""" |
| 834 |
Paragraphs contain text and may contain footnote references (manually |
| 835 |
numbered [1]_, anonymous auto-numbered [#]_, labeled auto-numbered |
| 836 |
[#label]_, or symbolic [*]_). |
| 837 |
|
| 838 |
.. [1] A footnote. |
| 839 |
|
| 840 |
.. [#label] Footnotes may be numbered, either manually or |
| 841 |
automatically using a "#"-prefixed label. This footnote has a |
| 842 |
label so it can be referred to from multiple places, both as a |
| 843 |
footnote reference ([#label]_) and as a `hyperlink reference`__. |
| 844 |
|
| 845 |
__ label_ |
| 846 |
|
| 847 |
.. [#] This footnote is numbered automatically and anonymously using a |
| 848 |
label of "#" only. |
| 849 |
|
| 850 |
.. [*] Footnotes may also use symbols, specified with a "*" label. |
| 851 |
""", |
| 852 |
r""" |
| 853 |
Paragraphs contain text and may contain footnote references (manually |
| 854 |
numbered\DUfootnotemark{footnote-reference-1}{footnote-1}{1}, anonymous auto-numbered\DUfootnotemark{footnote-reference-2}{footnote-2}{3}, labeled auto-numbered\DUfootnotemark{footnote-reference-3}{label}{2}, or symbolic\DUfootnotemark{footnote-reference-4}{footnote-3}{*}). |
| 855 |
% |
| 856 |
\DUfootnotetext{footnote-1}{footnote-reference-1}{1}{% |
| 857 |
A footnote. |
| 858 |
} |
| 859 |
% |
| 860 |
\DUfootnotetext{label}{footnote-reference-3}{2}{% |
| 861 |
Footnotes may be numbered, either manually or |
| 862 |
automatically using a \textquotedbl{}\#\textquotedbl{}-prefixed label. This footnote has a |
| 863 |
label so it can be referred to from multiple places, both as a |
| 864 |
footnote reference (\DUfootnotemark{footnote-reference-5}{label}{2}) and as a \hyperref[label]{hyperlink reference}. |
| 865 |
} |
| 866 |
% |
| 867 |
\DUfootnotetext{footnote-2}{footnote-reference-2}{3}{% |
| 868 |
This footnote is numbered automatically and anonymously using a |
| 869 |
label of \textquotedbl{}\#\textquotedbl{} only. |
| 870 |
} |
| 871 |
% |
| 872 |
\DUfootnotetext{footnote-3}{footnote-reference-4}{*}{% |
| 873 |
Footnotes may also use symbols, specified with a \textquotedbl{}*\textquotedbl{} label. |
| 874 |
} |
| 875 |
"""], |
| 876 |
|
| 877 |
["""\ |
| 878 |
It's possible to produce nested footnotes in LaTeX. [#]_ |
| 879 |
|
| 880 |
.. [#] It takes some work, though. [#]_ |
| 881 |
.. [#] And don't even get me started on how tricky recursive footnotes |
| 882 |
would be. |
| 883 |
""", |
| 884 |
r""" |
| 885 |
It's possible to produce nested footnotes in LaTeX.\DUfootnotemark{footnote-reference-1}{footnote-1}{1} |
| 886 |
% |
| 887 |
\DUfootnotetext{footnote-1}{footnote-reference-1}{1}{% |
| 888 |
It takes some work, though.\DUfootnotemark{footnote-reference-2}{footnote-2}{2} |
| 889 |
} |
| 890 |
% |
| 891 |
\DUfootnotetext{footnote-2}{footnote-reference-2}{2}{% |
| 892 |
And don't even get me started on how tricky recursive footnotes |
| 893 |
would be. |
| 894 |
} |
| 895 |
"""], |
| 896 |
|
| 897 |
["""\ |
| 898 |
It's possible to produce chained footnotes in LaTeX. [#]_ |
| 899 |
|
| 900 |
.. [#] They're just a special case of nested footnotes. [#]_ |
| 901 |
.. [#] A nested footnote is a footnote on a footnote. [#]_ |
| 902 |
.. [#] This is a footnote on a footnote on a footnote. |
| 903 |
""", |
| 904 |
r""" |
| 905 |
It's possible to produce chained footnotes in LaTeX.\DUfootnotemark{footnote-reference-1}{footnote-1}{1} |
| 906 |
% |
| 907 |
\DUfootnotetext{footnote-1}{footnote-reference-1}{1}{% |
| 908 |
They're just a special case of nested footnotes.\DUfootnotemark{footnote-reference-2}{footnote-2}{2} |
| 909 |
} |
| 910 |
% |
| 911 |
\DUfootnotetext{footnote-2}{footnote-reference-2}{2}{% |
| 912 |
A nested footnote is a footnote on a footnote.\DUfootnotemark{footnote-reference-3}{footnote-3}{3} |
| 913 |
} |
| 914 |
% |
| 915 |
\DUfootnotetext{footnote-3}{footnote-reference-3}{3}{% |
| 916 |
This is a footnote on a footnote on a footnote. |
| 917 |
} |
| 918 |
"""], |
| 919 |
|
| 920 |
["""\ |
| 921 |
A footnote [#multi]_ |
| 922 |
|
| 923 |
.. [#multi] This is a footnote with nested [#]_ footnotes. [#]_ [#]_ |
| 924 |
|
| 925 |
.. [#] First nested [#]_ footnote. [#]_ |
| 926 |
|
| 927 |
.. [#] Second nested footnote. [#]_ |
| 928 |
|
| 929 |
.. [#] Third nested footnote. |
| 930 |
|
| 931 |
.. [#] First double-nested footnote. |
| 932 |
|
| 933 |
.. [#] Second double-nested footnote. |
| 934 |
|
| 935 |
.. [#] First triple-nested footnote. |
| 936 |
|
| 937 |
.. [#] Not nested, referenced after footnote text. |
| 938 |
|
| 939 |
Ref to a new footnote [#]_ |
| 940 |
|
| 941 |
A second reference to the first one [#multi]_. |
| 942 |
We can also write a hyperlink to multi_. |
| 943 |
""", |
| 944 |
r""" |
| 945 |
A footnote\DUfootnotemark{footnote-reference-1}{multi}{1} |
| 946 |
% |
| 947 |
\DUfootnotetext{multi}{footnote-reference-1}{1}{% |
| 948 |
This is a footnote with nested\DUfootnotemark{footnote-reference-2}{footnote-1}{2} footnotes.\DUfootnotemark{footnote-reference-3}{footnote-2}{3}\DUfootnotemark{footnote-reference-4}{footnote-3}{4} |
| 949 |
} |
| 950 |
% |
| 951 |
\DUfootnotetext{footnote-1}{footnote-reference-2}{2}{% |
| 952 |
First nested\DUfootnotemark{footnote-reference-5}{footnote-4}{5} footnote.\DUfootnotemark{footnote-reference-6}{footnote-5}{6} |
| 953 |
} |
| 954 |
% |
| 955 |
\DUfootnotetext{footnote-2}{footnote-reference-3}{3}{% |
| 956 |
Second nested footnote.\DUfootnotemark{footnote-reference-7}{footnote-6}{7} |
| 957 |
} |
| 958 |
% |
| 959 |
\DUfootnotetext{footnote-3}{footnote-reference-4}{4}{% |
| 960 |
Third nested footnote. |
| 961 |
} |
| 962 |
% |
| 963 |
\DUfootnotetext{footnote-4}{footnote-reference-5}{5}{% |
| 964 |
First double-nested footnote. |
| 965 |
} |
| 966 |
% |
| 967 |
\DUfootnotetext{footnote-5}{footnote-reference-6}{6}{% |
| 968 |
Second double-nested footnote. |
| 969 |
} |
| 970 |
% |
| 971 |
\DUfootnotetext{footnote-6}{footnote-reference-7}{7}{% |
| 972 |
First triple-nested footnote. |
| 973 |
} |
| 974 |
% |
| 975 |
\DUfootnotetext{footnote-7}{footnote-reference-8}{8}{% |
| 976 |
Not nested, referenced after footnote text. |
| 977 |
} |
| 978 |
|
| 979 |
Ref to a new footnote\DUfootnotemark{footnote-reference-8}{footnote-7}{8} |
| 980 |
|
| 981 |
A second reference to the first one\DUfootnotemark{footnote-reference-9}{multi}{1}. |
| 982 |
We can also write a hyperlink to \hyperref[multi]{multi}. |
| 983 |
"""], |
| 984 |
]) |
| 985 |
|
| 986 |
|
| 987 |
samples['latex-footnotes'] = ({'latex_footnotes': True}, [ |
| 988 |
|
| 989 |
[r""" |
| 990 |
Paragraphs contain text and may contain footnote references (manually |
| 991 |
numbered [1]_, anonymous auto-numbered [#]_, labeled auto-numbered |
| 992 |
[#label]_, or symbolic [*]_). |
| 993 |
|
| 994 |
.. [1] A footnote. |
| 995 |
|
| 996 |
.. [#label] Footnotes may be numbered, either manually or |
| 997 |
automatically using a "#"-prefixed label. This footnote has a |
| 998 |
label so it can be referred to from multiple places, both as a |
| 999 |
footnote reference ([#label]_) and as a `hyperlink reference`__. |
| 1000 |
|
| 1001 |
__ label_ |
| 1002 |
|
| 1003 |
.. [#] This footnote is numbered automatically and anonymously using a |
| 1004 |
label of "#" only. |
| 1005 |
|
| 1006 |
.. [*] With "latex-footnotes", symbolic footnotes and numbered footnotes |
| 1007 |
are merged, the choice of symbol vs. number is done by LaTeX styling. |
| 1008 |
""", |
| 1009 |
r""" |
| 1010 |
Paragraphs contain text and may contain footnote references (manually |
| 1011 |
numbered% |
| 1012 |
\footnote{\label{footnote-1}% |
| 1013 |
A footnote. |
| 1014 |
}, anonymous auto-numbered% |
| 1015 |
\footnote{% |
| 1016 |
This footnote is numbered automatically and anonymously using a |
| 1017 |
label of \textquotedbl{}\#\textquotedbl{} only. |
| 1018 |
}, labeled auto-numbered% |
| 1019 |
\footnote{\label{label}% |
| 1020 |
Footnotes may be numbered, either manually or |
| 1021 |
automatically using a \textquotedbl{}\#\textquotedbl{}-prefixed label. This footnote has a |
| 1022 |
label so it can be referred to from multiple places, both as a |
| 1023 |
footnote reference (\footref{label}) and as a \hyperref[label]{hyperlink reference}. |
| 1024 |
}, or symbolic% |
| 1025 |
\footnote{% |
| 1026 |
With \textquotedbl{}latex-footnotes\textquotedbl{}, symbolic footnotes and numbered footnotes |
| 1027 |
are merged, the choice of symbol vs. number is done by LaTeX styling. |
| 1028 |
}). |
| 1029 |
"""], |
| 1030 |
|
| 1031 |
["""\ |
| 1032 |
A footnote [#multi]_ |
| 1033 |
|
| 1034 |
.. [#multi] This is a footnote with nested [#]_ footnotes. [#]_ [#]_ |
| 1035 |
.. [#] First nested [#]_ footnote. [#]_ |
| 1036 |
.. [#] Second nested footnote. [#]_ |
| 1037 |
.. [#] Third nested footnote. |
| 1038 |
.. [#] First double-nested footnote. |
| 1039 |
.. [#] Second double-nested footnote. |
| 1040 |
.. [#] First triple-nested footnote. |
| 1041 |
.. [#] Not nested, referenced after footnote text. |
| 1042 |
|
| 1043 |
Ref to a new footnote [#]_ |
| 1044 |
|
| 1045 |
A second reference to the first one [#multi]_. |
| 1046 |
We can also write a hyperlink to multi_. |
| 1047 |
""", |
| 1048 |
r""" |
| 1049 |
A footnote% |
| 1050 |
\footnote{\label{multi}% |
| 1051 |
This is a footnote with nested\footref{footnote-1} footnotes.\footref{footnote-2}\footref{footnote-3} |
| 1052 |
}% |
| 1053 |
\refstepcounter{footnote}\footnotetext{\label{footnote-1}% |
| 1054 |
First nested\footref{footnote-4} footnote.\footref{footnote-5} |
| 1055 |
}% |
| 1056 |
\refstepcounter{footnote}\footnotetext{\label{footnote-2}% |
| 1057 |
Second nested footnote.\footref{footnote-6} |
| 1058 |
}% |
| 1059 |
\refstepcounter{footnote}\footnotetext{\label{footnote-3}% |
| 1060 |
Third nested footnote. |
| 1061 |
}% |
| 1062 |
\refstepcounter{footnote}\footnotetext{\label{footnote-4}% |
| 1063 |
First double-nested footnote. |
| 1064 |
}% |
| 1065 |
\refstepcounter{footnote}\footnotetext{\label{footnote-5}% |
| 1066 |
Second double-nested footnote. |
| 1067 |
}% |
| 1068 |
\refstepcounter{footnote}\footnotetext{\label{footnote-6}% |
| 1069 |
First triple-nested footnote. |
| 1070 |
} |
| 1071 |
|
| 1072 |
Ref to a new footnote% |
| 1073 |
\footnote{% |
| 1074 |
Not nested, referenced after footnote text. |
| 1075 |
} |
| 1076 |
|
| 1077 |
A second reference to the first one\footref{multi}. |
| 1078 |
We can also write a hyperlink to \hyperref[multi]{multi}. |
| 1079 |
"""], |
| 1080 |
]) |
| 1081 |
|
| 1082 |
if __name__ == '__main__': |
| 1083 |
unittest.main() |