2

Here is an example,

#+LATEX_CMD: xelatex
#+LATEX_HEADER: \usepackage{xltxtra}
#+LATEX_HEADER: \setmainfont{AR PL KaitiM GB}
This is a *test*

这是*测试*

The resulted HTML output is the following:

<p>
This is a <b>test</b>
</p>

<p>
这是*测试*
</p>

I also tried output to PDF, the problem is the same: no effect for the Chinese text.

I also tried the other markup, emphasise, underline, the problem is the same.

I wonder what is the solution for the problem?

1 Answer 1

3

I think that the issue isn't with Chinese as such, but with the fact that in Chinese spacing between words isn't obligatory (I think — unfortunately I don't know Chinese), while in Org, by default at least, emphasis markers have to be delimited by whitespace or punctuation.

Hence, this question on stackoverflow is relevant.

There are two solutions presented there: a backend specific one and a more general one.

Backend specific

This will only work for a specific export format. For instance, for HTML export, you could do this:

This is a *test*

这是@@html:<b>@@测试@@html:</b>@@

For PDF export:

#+LATEX_CMD: xelatex
#+LATEX_HEADER: \usepackage{xltxtra}
#+LATEX_HEADER: \setmainfont{AR PL KaitiM GB}
This is a *test*

这是@@latex:\textbf{测试}@@

This is obviously extremely inconvenient, unportable and rather ugly.

General

Quoting from the answer (as it's extensive and very well explained):

(setcar org-emphasis-regexp-components " \t('\"{[:alpha:]")
(setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\\")
(org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)

Explanation

The manual says that org-emphasis-regexp-components can be used to

fine tune what characters are allowed before and after the markup characters [...].

It is a list containing five entries. The first entry lists characters that are allowed to immediately precede markup characters, and the second entry lists characters that are allowed to follow markup characters. By default, letters are not included in either one of these entries. So in order to successfully apply formatting to strings immediately preceded or followed by a letter, we have to add [:alpha:] (which matches any letter) to both entries.

This is what the calls to setcar do. The purpose of the third line is to rebuild the regular expression for emphasis based on the modified version of org-emphasis-regexp-components.

The only slight weakness of this solution is that when you have multiple emphases on a single line (or even adjacent lines), for example:

abc*def*ghi jkl*mno*pqr

then in the Emacs buffer (in Emacs 24.4 and 26.1), everything between the two emphases will also be spuriously, visually emphasised (i.e. in the example, not only will def and mno be emphasised, but also ghi jkl). However, in the export (both HTML and PDF), the emphasis (bolding) will be correct (i.e. only def and mno are bold), so it's a minor issue.

3
  • Your diagnostic is right on spot! Yes, it's because of the lack of space in the Chinese characters. I added one space before the markup, then I was able to produce the desired effect for the export to HTML. I still have some problem with export to PDF, it produced no visible bold effect even for the English text. Maybe, the font that I have chosen does not support bold?
    – Yu Shen
    Jun 22, 2018 at 18:10
  • 1
    It is possible that your font doesn't support bold. Perhaps you could check by trying to add the explicit LaTeX markup (e.g. @@latex:\textbf{测试}@@) or by editing the intermediate .tex file and adding the \textbf{} there? Also, you could look at the intermediate .tex file and check if the relevant text is correctly marked up (for instance with \textbf{}).
    – aplaice
    Jun 22, 2018 at 18:51
  • 1
    You're right. It's a problem with the font. I did see \textbf{测试} in the resulted test.tex, and also tried to use @@latex:\textbf{测试}@@ in test.org, there is no visible bold effect either. Thanks!
    – Yu Shen
    Jun 22, 2018 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.