-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Chinese latex default support (refs: #3244 #3251) #3272
Conversation
Default xelatex+ctex in latex builder for Chinese when there is no user defined latex engine/latex_elements Detect ctex package for Chinese in latex writer and give warnings when not found. Did not force to ctex package and leave it configurable in conf.py for users Clear babel/polyglossia settings for Chinese in latex writer, as they are not suitable for Chinese language Default ctex package setting in conf.py generated by quickstart, otherwise default empty latex_elements in conf.py would override default settings in latex builder
according to flake8 reports
according to flake8 reports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You made this PR to stable branch.
But I feel this makes incompatibilities as you said to Chinese users who already customized their project.
different combinations of latex compiler/chinese support package/document settings may not work together.
only several designed combinations of configuration works for chinese latex documents
So I think this should move to master branch, and we should announce about this new default settings.
""" Better default latex_elements settings for specific languages. """ | ||
if config.language: | ||
if config.language.split('_')[0] == 'zh': | ||
return {'usepackages': '\\usepackage{ctex}'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said before, usepackage
key is used only for internal. Don't use here.
It will be OVERRIDED if some extension uses Sphinx.add_latex_package()
API.
We should use other key for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a dedicated key for this case then
@@ -132,6 +132,11 @@ latex_elements = { | |||
# Latex figure (float) alignment | |||
# | |||
# 'figure_align': 'htbp', | |||
|
|||
# Chinese language default package ctex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? ctex is already loaded by default settings (see default_latex_elements()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the empty dictionary by default overrides default_latex_elements()
.
Another option would be comment whole latex_elements={ }
in conf.py_t
@@ -446,6 +446,18 @@ def __init__(self, document, builder): | |||
self.elements['multilingual'] = '%s\n\\setmainlanguage{%s}' % \ | |||
(self.elements['polyglossia'], self.babel.get_language()) | |||
|
|||
# detect Chinese language, disable babel/polyglossia |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings of babel and polyglossia are already finished here.
If you'd like to disable them, you should move these block to above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I'll check the code later.
And about the PR to stable branch. In this version the latex builder/writer does not overrides conf.py so I think it is compatible.
I'll think about where to put usepackage
and if I add a new conf key then maybe it is better to PR to master branch
if builder.config.language: | ||
if builder.config.language.split('_')[0] == 'zh': | ||
self.elements['babel'] = '' | ||
self.elements['polyglossia'] = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clears both keys always.
Did you mean all Chinese users could not use babel and polyglossia even if they configured intentionally?
I feel this is very strong restriction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I mean it. There is no possible to use babel/polyglossia with chinese.
if builder.config.language.split('_')[0] == 'zh': | ||
self.elements['babel'] = '' | ||
self.elements['polyglossia'] = '' | ||
if 'ctex' not in self.elements['usepackages'].lower(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is same above.
Isn't there any choices to build Chinese docs without ctex?
In this comment, #3251 (comment), you said CJKutf8 package allows to build Chinese docs.
This warns to the such users. Is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is intended. ctex is the usually choice in most cases.
Chinese user would always get an warning by babel because babel does not support Chinese.
So I think it is usual that common user would use ctex and advanced user would understand what this warning means.
If your opinion is no warning in proper working cases, I'll think about it more deep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can clear this warning and add some notes to user manual?
and, is it good to clear babel warnings for chinese?
MEMO |
Sorry, I just removed |
Subject: Add Chinese latex default support
Bugfix
Purpose
Detail
Problem Solved: Could not generate Chinese latex documents correctly by default
Relates