Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

cdarlint
Copy link

Subject: Add Chinese latex default support

Bugfix

Purpose

  • Add Chinese default latex support

Detail

Problem Solved: Could not generate Chinese latex documents correctly by default

  • 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

Relates

cdarlint and others added 6 commits December 21, 2016 10:37
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
Copy link
Member

@tk0miya tk0miya left a 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}'}
Copy link
Member

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.

Copy link
Author

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
Copy link
Member

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()).

Copy link
Author

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
Copy link
Member

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.

Copy link
Author

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'] = ''
Copy link
Member

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.

Copy link
Author

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():
Copy link
Member

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?

Copy link
Author

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

Copy link
Author

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?

@cdarlint
Copy link
Author

cdarlint commented Jan 12, 2017

MEMO
issues for now (change requested)
1 do not use key "usepackage"
2 default in conf.py_t or default in latex builder/writer?
3 give warning if not using ctex? or place note in documentation? and, other possible compile conf available for zh_CN (not only chs, but also cht for TW/HK/SG/etc.)

also see #1119
and be aware of new texlive-2013 as in #3070

@tk0miya
Copy link
Member

tk0miya commented Feb 13, 2018

Sorry, I just removed stable branch last night. As a result, github closes this automatically. It was not intended. so I reopened this again and changed target branch to 1.7 (we decided to rename stable branch to versioned one).
Thanks,

@tk0miya tk0miya closed this Sep 12, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants