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 default quickstart support for Chinese LaTex support. #3244

Closed
wants to merge 2 commits into from

Conversation

cdarlint
Copy link

Most common use of Chinese LaTeX is xelatex+ctex with encoding UTF-8, and there are many other possible configurations for different tasks.
For example, another option is to use pdflatex+ctex with encoding GBK.
Generally no one uses basic "latex" command to generate chinese pdfs as it is outdated, unmaintained and too complicated to configure.

Most common use of Chinese LaTeX is xelatex+ctex with encoding UTF-8, and there are many other possible configurations for different tasks.
For example, another option is to use pdflatex+ctex with encoding GBK.
Generally no one uses basic "latex" command to generate chinese pdfs as it is outdated, unmaintained and too complicated to configure.
@tk0miya tk0miya added builder:latex type:proposal a feature suggestion labels Dec 15, 2016
@cdarlint
Copy link
Author

I've considered adding this configuration to writers/latex.py.
There are two main reason I put it in quickstart:
1 default latex-engine after quickstart does not compile chinese documents, but babel or other language options in writers/latex.py locates after latex-engine cofiguration, which does not apply to chinese documents
2 not every chinese documents needs to be compiled by xelatex+ctex (many other options available), it should be configurable by end-user as in conf.py

repair a bug in previous commit:
default language set to '', avoiding issues when language is None
@tk0miya
Copy link
Member

tk0miya commented Dec 15, 2016

Thank you for proposal.

Now sphinx also provides default settings to Japanese.
https://github.com/sphinx-doc/sphinx/blob/1.5.1/sphinx/builders/latex.py#L275

I believe it would be nice if we can merge your settings into setup() function in latex builder.
I will refactor it to add default settings for specific languages in this weekend.
So please wait for that.

@tk0miya
Copy link
Member

tk0miya commented Dec 15, 2016

BTW, Is this change stable?
We should not merge this into stable branch if this brings breaking changes.
I don't know about chinese docs much, but I'm afraid that the new default settings affect to chinese users and docs.

@cdarlint
Copy link
Author

before this change it is not possible to generate chinese pdf by default.
this change only has affect to latex output with language start with "zh_", no affect on other output format/language
after this change it is possible to generate a tex file with chinese characters that can compiles with xelatex

There are some blogs talking about workarounds on sphinx chinese pdf generation, they alter the output tex file manually.
I'd appreciate if it generate a tex that compiles without manual modification.

Thank you for your reply, I'll check builders/latex.py recently, which I didn't read before.
I'm working on a chinese document and I'll follow up this issue.

@cdarlint
Copy link
Author

for chinese latex output,
some people modify generated .tex file, while some other people modify conf.py to generate a .tex that compiles
I propose the quickstart.py to generate a conf.py that works for zh_* languages by default

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.

As I commented above, I prefer to provide the default settings in setup() function in LaTeX builder.
I think conf.py should be used for "customization". We should not add a default settings to the file.

So please update this PR based on #3251.

@@ -141,7 +141,13 @@ latex_documents = [
(master_doc, '{{ project_fn }}.tex', u'{{ project_doc_texescaped_str }}',
u'{{ author_texescaped_str }}', 'manual'),
]

{% if language|default('').split('_')[0] == 'zh' %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jinja2 raises TemplateSyntaxError in this line:

TemplateSyntaxError: expected token 'end of statement block', got '.'

https://travis-ci.org/sphinx-doc/sphinx/jobs/184147701#L2019

Does this really work correct in your environment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this runs correct in my environment, but I haven't touched tox before and I can not configure it to work correctly for now
I run this program successfully, on windows anaconda python3

# Leave it configurable here for user customization
if language.split('_')[0] == 'zh':
latex_engine = 'xelatex'
latex_elements = {'usepackages':'\\usepackage{ctex}','polyglossia':''}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usepackage is an internal variable, so we can't say this always works fine.
It might be overwritten by any extensions. (It is used for `Sphinx.add_latex_package() API.)

How about this? I believe it might work fine.

latex_elements = {'polyglossia': '\\usepackage{ctex}'}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base on this version, it does not work. Because it set 'multilingual' and 'babel' to empty string on 'ja' only.

So 'zh_*' would have a multilingual property and got an error on method "babel_renewcommand".
This method generate tex file lines like:
\addto\captionsenglish{\renewcommand{\figurename}{图 }}
This is not correct.

I believe after your refactor last weekend, it will be easier to find a place to add chinese support.
I'll check the latest version later, thanks.

tk0miya added a commit that referenced this pull request Dec 24, 2016
LaTeX builder: Refactor the default settings generators (refs: #3244)
@tk0miya
Copy link
Member

tk0miya commented Dec 24, 2016

Now we start to discuss in new PR #3272.
So I close this.

Thanks,

@tk0miya tk0miya closed this Dec 24, 2016
@cdarlint cdarlint deleted the stable branch December 25, 2016 07:06
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
builder:latex type:proposal a feature suggestion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants