|
16 | 16 | import os
|
17 | 17 | import sphinx
|
18 | 18 |
|
19 |
| -from subprocess import check_output |
20 |
| - |
21 | 19 | # Get Sphinx version
|
22 | 20 | major, minor, patch = sphinx.version_info[:3]
|
23 | 21 |
|
|
343 | 341 | verbatimhintsturnover=false,
|
344 | 342 | ''',
|
345 | 343 |
|
| 344 | + # For CJK One-half spacing, need to be in front of hyperref |
| 345 | + 'extrapackages': r'\usepackage{setspace}', |
| 346 | + |
346 | 347 | # Additional stuff for the LaTeX preamble.
|
347 | 348 | 'preamble': '''
|
348 | 349 | % Prevent column squeezing of tabulary.
|
|
355 | 356 | ''',
|
356 | 357 | }
|
357 | 358 |
|
358 |
| -# At least one book (translations) may have Asian characters |
359 |
| -# with are only displayed if xeCJK is used |
| 359 | +# Translations have Asian (CJK) characters which are only displayed if |
| 360 | +# xeCJK is used |
360 | 361 |
|
361 |
| -cjk_cmd = check_output(['fc-list', '--format="%{family[0]}\n"']).decode('utf-8', 'ignore') |
362 |
| -if cjk_cmd.find("Noto Sans CJK SC") >= 0: |
363 |
| - latex_elements['preamble'] += ''' |
| 362 | +latex_elements['preamble'] += ''' |
| 363 | + \\IfFontExistsTF{Noto Sans CJK SC}{ |
364 | 364 | % This is needed for translations
|
365 |
| - \\usepackage{xeCJK} |
366 |
| - \\setCJKmainfont{Noto Sans CJK SC} |
| 365 | + \\usepackage{xeCJK} |
| 366 | + \\IfFontExistsTF{Noto Serif CJK SC}{ |
| 367 | + \\setCJKmainfont{Noto Serif CJK SC}[AutoFakeSlant] |
| 368 | + }{ |
| 369 | + \\setCJKmainfont{Noto Sans CJK SC}[AutoFakeSlant] |
| 370 | + } |
| 371 | + \\setCJKsansfont{Noto Sans CJK SC}[AutoFakeSlant] |
| 372 | + \\setCJKmonofont{Noto Sans Mono CJK SC}[AutoFakeSlant] |
| 373 | + % CJK Language-specific font choices |
| 374 | + \\IfFontExistsTF{Noto Serif CJK SC}{ |
| 375 | + \\newCJKfontfamily[SCmain]\\scmain{Noto Serif CJK SC}[AutoFakeSlant] |
| 376 | + \\newCJKfontfamily[SCserif]\\scserif{Noto Serif CJK SC}[AutoFakeSlant] |
| 377 | + }{ |
| 378 | + \\newCJKfontfamily[SCmain]\\scmain{Noto Sans CJK SC}[AutoFakeSlant] |
| 379 | + \\newCJKfontfamily[SCserif]\\scserif{Noto Sans CJK SC}[AutoFakeSlant] |
| 380 | + } |
| 381 | + \\newCJKfontfamily[SCsans]\\scsans{Noto Sans CJK SC}[AutoFakeSlant] |
| 382 | + \\newCJKfontfamily[SCmono]\\scmono{Noto Sans Mono CJK SC}[AutoFakeSlant] |
| 383 | + \\IfFontExistsTF{Noto Serif CJK TC}{ |
| 384 | + \\newCJKfontfamily[TCmain]\\tcmain{Noto Serif CJK TC}[AutoFakeSlant] |
| 385 | + \\newCJKfontfamily[TCserif]\\tcserif{Noto Serif CJK TC}[AutoFakeSlant] |
| 386 | + }{ |
| 387 | + \\newCJKfontfamily[TCmain]\\tcmain{Noto Sans CJK TC}[AutoFakeSlant] |
| 388 | + \\newCJKfontfamily[TCserif]\\tcserif{Noto Sans CJK TC}[AutoFakeSlant] |
| 389 | + } |
| 390 | + \\newCJKfontfamily[TCsans]\\tcsans{Noto Sans CJK TC}[AutoFakeSlant] |
| 391 | + \\newCJKfontfamily[TCmono]\\tcmono{Noto Sans Mono CJK TC}[AutoFakeSlant] |
| 392 | + \\IfFontExistsTF{Noto Serif CJK KR}{ |
| 393 | + \\newCJKfontfamily[KRmain]\\krmain{Noto Serif CJK KR}[AutoFakeSlant] |
| 394 | + \\newCJKfontfamily[KRserif]\\krserif{Noto Serif CJK KR}[AutoFakeSlant] |
| 395 | + }{ |
| 396 | + \\newCJKfontfamily[KRmain]\\krmain{Noto Sans CJK KR}[AutoFakeSlant] |
| 397 | + \\newCJKfontfamily[KRserif]\\krserif{Noto Sans CJK KR}[AutoFakeSlant] |
| 398 | + } |
| 399 | + \\newCJKfontfamily[KRsans]\\krsans{Noto Sans CJK KR}[AutoFakeSlant] |
| 400 | + \\newCJKfontfamily[KRmono]\\krmono{Noto Sans Mono CJK KR}[AutoFakeSlant] |
| 401 | + \\IfFontExistsTF{Noto Serif CJK JP}{ |
| 402 | + \\newCJKfontfamily[JPmain]\\jpmain{Noto Serif CJK JP}[AutoFakeSlant] |
| 403 | + \\newCJKfontfamily[JPserif]\\jpserif{Noto Serif CJK JP}[AutoFakeSlant] |
| 404 | + }{ |
| 405 | + \\newCJKfontfamily[JPmain]\\jpmain{Noto Sans CJK JP}[AutoFakeSlant] |
| 406 | + \\newCJKfontfamily[JPserif]\\jpserif{Noto Sans CJK JP}[AutoFakeSlant] |
| 407 | + } |
| 408 | + \\newCJKfontfamily[JPsans]\\jpsans{Noto Sans CJK JP}[AutoFakeSlant] |
| 409 | + \\newCJKfontfamily[JPmono]\\jpmono{Noto Sans Mono CJK JP}[AutoFakeSlant] |
| 410 | + % Dummy commands for Sphinx < 2.3 (no 'extrapackages' support) |
| 411 | + \\providecommand{\\onehalfspacing}{} |
| 412 | + \\providecommand{\\singlespacing}{} |
367 | 413 | % Define custom macros to on/off CJK
|
368 |
| - \\newcommand{\\kerneldocCJKon}{\\makexeCJKactive} |
369 |
| - \\newcommand{\\kerneldocCJKoff}{\\makexeCJKinactive} |
370 |
| - % To customize \sphinxtableofcontents |
| 414 | + \\newcommand{\\kerneldocCJKon}{\\makexeCJKactive\\onehalfspacing} |
| 415 | + \\newcommand{\\kerneldocCJKoff}{\\makexeCJKinactive\\singlespacing} |
| 416 | + \\newcommand{\\kerneldocBeginSC}{% |
| 417 | + \\begingroup% |
| 418 | + \\scmain% |
| 419 | + } |
| 420 | + \\newcommand{\\kerneldocEndSC}{\\endgroup} |
| 421 | + \\newcommand{\\kerneldocBeginTC}{% |
| 422 | + \\begingroup% |
| 423 | + \\tcmain% |
| 424 | + \\renewcommand{\\CJKrmdefault}{TCserif}% |
| 425 | + \\renewcommand{\\CJKsfdefault}{TCsans}% |
| 426 | + \\renewcommand{\\CJKttdefault}{TCmono}% |
| 427 | + } |
| 428 | + \\newcommand{\\kerneldocEndTC}{\\endgroup} |
| 429 | + \\newcommand{\\kerneldocBeginKR}{% |
| 430 | + \\begingroup% |
| 431 | + \\xeCJKDeclareCharClass{HalfLeft}{`“,`‘}% |
| 432 | + \\xeCJKDeclareCharClass{HalfRight}{`”,`’}% |
| 433 | + \\krmain% |
| 434 | + \\renewcommand{\\CJKrmdefault}{KRserif}% |
| 435 | + \\renewcommand{\\CJKsfdefault}{KRsans}% |
| 436 | + \\renewcommand{\\CJKttdefault}{KRmono}% |
| 437 | + \\xeCJKsetup{CJKspace = true} % For inter-phrase space |
| 438 | + } |
| 439 | + \\newcommand{\\kerneldocEndKR}{\\endgroup} |
| 440 | + \\newcommand{\\kerneldocBeginJP}{% |
| 441 | + \\begingroup% |
| 442 | + \\xeCJKDeclareCharClass{HalfLeft}{`“,`‘}% |
| 443 | + \\xeCJKDeclareCharClass{HalfRight}{`”,`’}% |
| 444 | + \\jpmain% |
| 445 | + \\renewcommand{\\CJKrmdefault}{JPserif}% |
| 446 | + \\renewcommand{\\CJKsfdefault}{JPsans}% |
| 447 | + \\renewcommand{\\CJKttdefault}{JPmono}% |
| 448 | + } |
| 449 | + \\newcommand{\\kerneldocEndJP}{\\endgroup} |
| 450 | + % Single spacing in literal blocks |
| 451 | + \\fvset{baselinestretch=1} |
| 452 | + % To customize \\sphinxtableofcontents |
371 | 453 | \\usepackage{etoolbox}
|
372 | 454 | % Inactivate CJK after tableofcontents
|
373 | 455 | \\apptocmd{\\sphinxtableofcontents}{\\kerneldocCJKoff}{}{}
|
374 |
| - ''' |
375 |
| -else: |
376 |
| - latex_elements['preamble'] += ''' |
| 456 | + }{ % No CJK font found |
377 | 457 | % Custom macros to on/off CJK (Dummy)
|
378 | 458 | \\newcommand{\\kerneldocCJKon}{}
|
379 | 459 | \\newcommand{\\kerneldocCJKoff}{}
|
380 |
| - ''' |
| 460 | + \\newcommand{\\kerneldocBeginSC}{} |
| 461 | + \\newcommand{\\kerneldocEndSC}{} |
| 462 | + \\newcommand{\\kerneldocBeginTC}{} |
| 463 | + \\newcommand{\\kerneldocEndTC}{} |
| 464 | + \\newcommand{\\kerneldocBeginKR}{} |
| 465 | + \\newcommand{\\kerneldocEndKR}{} |
| 466 | + \\newcommand{\\kerneldocBeginSC}{} |
| 467 | + \\newcommand{\\kerneldocEndKR}{} |
| 468 | + } |
| 469 | +''' |
381 | 470 |
|
382 | 471 | # Fix reference escape troubles with Sphinx 1.4.x
|
383 | 472 | if major == 1:
|
|
0 commit comments