@@ -225,10 +225,40 @@ class Language:
225225 "-D latex_elements.fontenc=" ,
226226)
227227
228- PLATEX_DEFAULT = (
229- "-D latex_engine=platex " ,
228+ LUALATEX_FOR_JP = (
229+ "-D latex_engine=lualatex " ,
230230 "-D latex_elements.inputenc=" ,
231231 "-D latex_elements.fontenc=" ,
232+ "-D latex_docclass.manual=ltjsbook" ,
233+ "-D latex_docclass.howto=ltjsarticle" ,
234+
235+ # supress polyglossia warnings
236+ "-D latex_elements.polyglossia=" ,
237+ "-D latex_elements.fontpkg=" ,
238+
239+ # preamble
240+ "-D latex_elements.preamble="
241+
242+ # Render non-Japanese letters with luatex
243+ # https://gist.github.com/zr-tex8r/e0931df922f38fbb67634f05dfdaf66b
244+ r"\\usepackage[noto-otf]{luatexja-preset}"
245+ r"\\usepackage{newunicodechar}"
246+ r"\\newunicodechar{^^^^212a}{K}"
247+
248+ # Workaround for the luatex-ja issue (Thanks to @jfbu)
249+ # https://github.com/sphinx-doc/sphinx/issues/11179#issuecomment-1420715092
250+ # https://osdn.net/projects/luatex-ja/ticket/47321
251+ r"\\makeatletter"
252+ r"\\titleformat{\\subsubsection}{\\normalsize\\py@HeaderFamily}"
253+ r"{\\py@TitleColor\\thesubsubsection}{0.5em}{\\py@TitleColor}"
254+ r"\\titleformat{\\paragraph}{\\normalsize\\py@HeaderFamily}"
255+ r"{\\py@TitleColor\\theparagraph}{0.5em}{\\py@TitleColor}"
256+ r"\\titleformat{\\subparagraph}{\\normalsize\\py@HeaderFamily}"
257+ r"{\\py@TitleColor\\thesubparagraph}{0.5em}{\\py@TitleColor}"
258+ r"\\makeatother"
259+
260+ # subpress warning: (fancyhdr)Make it at least 16.4pt
261+ r"\\setlength{\\footskip}{16.4pt}"
232262)
233263
234264XELATEX_WITH_FONTSPEC = (
@@ -257,7 +287,7 @@ class Language:
257287 Language ("fr" , "fr" , "French" , True , XELATEX_WITH_FONTSPEC ),
258288 Language ("id" , "id" , "Indonesian" , False , XELATEX_DEFAULT ),
259289 Language ("it" , "it" , "Italian" , False , XELATEX_DEFAULT ),
260- Language ("ja" , "ja" , "Japanese" , True , PLATEX_DEFAULT , html_only = True ), # See https://github.com/python/python-docs-ja/issues/35
290+ Language ("ja" , "ja" , "Japanese" , True , LUALATEX_FOR_JP ),
261291 Language ("ko" , "ko" , "Korean" , True , XELATEX_FOR_KOREAN ),
262292 Language ("pl" , "pl" , "Polish" , False , XELATEX_DEFAULT ),
263293 Language ("pt-br" , "pt_BR" , "Brazilian Portuguese" , True , XELATEX_DEFAULT ),
@@ -726,6 +756,17 @@ def build(self):
726756 "-D gettext_compact=0" ,
727757 )
728758 )
759+ if self .language .tag == "ja" :
760+ # Since luatex doesn't support \ufffd, replace \ufffd with '?'.
761+ # https://gist.github.com/zr-tex8r/e0931df922f38fbb67634f05dfdaf66b
762+ # Luatex already fixed this issue, so we can remove this once Texlive is updated.
763+ # (https://github.com/TeX-Live/luatex/commit/eaa95ce0a141eaf7a02)
764+ subprocess .check_output ("sed -i s/\N{REPLACEMENT CHARACTER} /?/g "
765+ f"{ locale_dirs } /ja/LC_MESSAGES/**/*.po" ,
766+ shell = True )
767+ subprocess .check_output ("sed -i s/\N{REPLACEMENT CHARACTER} /?/g "
768+ f"{ self .checkout } /Doc/**/*.rst" , shell = True )
769+
729770 if self .version .status == "EOL" :
730771 sphinxopts .append ("-D html_context.outdated=1" )
731772 maketarget = (
0 commit comments