Skip to content

Feature Request: support upLaTeX for PDF builds of Japanese projects #4186

@jfbu

Description

@jfbu

Many projects will use Unicode characters. Sphinx uses pLaTeX for Japanese documents but pLaTeX is not Unicode aware.

It appears upLaTeX adds Unicode support and can help handling problems with stray Unicode characters: in particular using \usepackage[utf8]{inputenc} and babel is possible with upLaTeX. From the little I understand it is easier with upLaTeX to have mixed languages documents, for example with parts in English and others in Japanese.

Currently one can induce Sphinx into using upLaTeX via this latexmkjarc file in the repertory of the project

$latex = 'uplatex ' . $ENV{'LATEXOPTS'} . ' %O %S';
$dvipdf = 'dvipdfmx %O -o %D %S';
$makeindex = 'rm -f %D; upmendex -f -d %B.dic -s python.ist %S || echo "upmendex exited with error code $? (ignoring)" && : >> %D';
add_cus_dep( "glo", "gls", 0, "makeglo" );
sub makeglo {
 return system( "upmendex -s gglo.ist -o '$_[0].gls' '$_[0].glo'" );
}

and an latex_additional_files = ['latexmkjarc'] line in conf.py. I am not sure the options to uplatex and upmendex above are optimal. I just took the current file which uses platex and mendex and dropped options not existing for uplatex/upmendex.

But we also need extra uplatex option in document class in case of 'manual' type (which uses jsbook.cls).

This option does not work for 'howto' documents and one must use ujreport.cls as replacement for jreport.cls. Currently this setting appears to require some monkey-patch by user of sphinx.builders.latex's default_latex_docclass. (see #4136 (comment))

Perhaps hyperref options for the encoding of PDF strings (particularly, bookmarks) is perhaps not good with upLaTeX. Currently sphinx.sty contains this logic:

% to make pdf with correct encoded bookmarks in Japanese
% this should precede the hyperref package
\ifx\kanjiskip\undefined
% for non-Japanese: make sure bookmarks are ok also with lualatex
  \PassOptionsToPackage{pdfencoding=unicode}{hyperref}
\else
  \RequirePackage{atbegshi}
  \ifx\ucs\undefined
    \ifnum 42146=\euc"A4A2
      \AtBeginShipoutFirst{\special{pdf:tounicode EUC-UCS2}}
    \else
      \AtBeginShipoutFirst{\special{pdf:tounicode 90ms-RKSJ-UCS2}}
    \fi
  \else
    \AtBeginShipoutFirst{\special{pdf:tounicode UTF8-UCS2}}
  \fi
\fi

I don't know if this is the good thing to do for upLaTeX. (I don't even know if it is so good for pLaTeX, for example I noticed there are problems with EN DASH).

Adding upLaTeX support could be good in particular for localization to Japanese of documents when localization is only partial. The CPython docs is an example.

Relates

the discussion at #4136

Environment info

  • Sphinx version: 1.6.5

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions