From: tumashu <tumashu@163.com>
To: "James Harkins" <jamshark70@zoho.com>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re:Bug: ODT export of Chinese text inserts spaces for line breaks
Date: Tue, 29 Jun 2021 12:43:41 +0800 (CST) [thread overview]
Message-ID: <557d5f5d.2eed.17a56147ed0.Coremail.tumashu@163.com> (raw)
In-Reply-To: <17a55e0b01d.11be78c6c72761.7557666657037565597@zoho.com>
[-- Attachment #1: Type: text/plain, Size: 2924 bytes --]
You can try the below config :-)
(defun eh-org-wash-text (text backend _info)
"导出 org file 时,删除中文之间不必要的空格。"
(when (or (org-export-derived-backend-p backend 'html)
(org-export-derived-backend-p backend 'odt))
(let ((regexp "[[:multibyte:]]")
(string text))
;; org-mode 默认将一个换行符转换为空格,但中文不需要这个空格,删除。
(setq string
(replace-regexp-in-string
(format "\\(%s\\) *\n *\\(%s\\)" regexp regexp)
"\\1\\2" string))
;; 删除粗体之后的空格
(dolist (str '("</b>" "</code>" "</del>" "</i>"))
(setq string
(replace-regexp-in-string
(format "\\(%s\\)\\(%s\\)[ ]+\\(%s\\)" regexp str regexp)
"\\1\\2\\3" string)))
;; 删除粗体之前的空格
(dolist (str '("<b>" "<code>" "<del>" "<i>" "<span class=\"underline\">"))
(setq string
(replace-regexp-in-string
(format "\\(%s\\)[ ]+\\(%s\\)\\(%s\\)" regexp str regexp)
"\\1\\2\\3" string)))
string)))
(add-hook 'org-export-filter-headline-functions #'eh-org-wash-text)
(add-hook 'org-export-filter-paragraph-functions #'eh-org-wash-text)
在 2021-06-29 11:47:06,"James Harkins" <jamshark70@zoho.com> 写道:
>Consider the following org document.
>
>* Test
>1本人不想亲自拿到学历学位证书、急于离校者,可书面委托他人代领学历学位证
>书,29日起即可离校;2本人想亲自领取学历学位证书者,按学校规定的程序及有关
>要求办理离校手续,领取相关证书后离校;
>
>This was produced by pasting in a single, long line, and then using alt-Q (a normal thing to do, and good for readability, because org-mode doesn't wrap lines by default).
>
>Exporting to ODT produces the following (body text, omitting titles, headers and such).
>
>1本人不想亲自拿到学历学位证书、急于离校者,可书面委托他人代领学历学位证 书,29日起即可离校;2本人想亲自领取学历学位证书者,按学校规定的程序及有关 要求办理离校手续,领取相关证书后离校;
>
>Between 证 and 书, and between 关 and 要, there is a space. Chinese typography does not allow for spaces mid-sentence.
>
>So, it would make sense to add a rule to the exporter: if one of the characters before or after a source-text line break is a Chinese, Japanese or Korean character, do not add a space. (The space is valid, of course, if the characters on either side of the line breaks are Roman or [I would guess] Cyrillic as well.)
>
>(Side note: Exporting to a LaTeX buffer shows that the line breaks have been copied into the .tex document as is -- but, provided that you have a `usepackage{xeCJK}` in the preamble, LaTeX produces correct, space-free output. So -- Org "gets away with it" because of LaTeX's handling of CJK text. It seems for ODT, Org needs to handle the spacing within its own logic.)
>
>This is org 9.1.9... bit old, I know, but I'm gonna take a wild guess that this has not been a high-visibility issue.
>
>hjh
[-- Attachment #2: Type: text/html, Size: 4423 bytes --]
next prev parent reply other threads:[~2021-06-29 4:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-29 3:47 Bug: ODT export of Chinese text inserts spaces for line breaks James Harkins
2021-06-29 4:43 ` tumashu [this message]
2021-06-29 17:01 ` Maxim Nikulin
2021-06-29 18:19 ` Eric Abrahamsen
2021-06-30 12:22 ` Maxim Nikulin
2022-10-08 13:14 ` Ihor Radchenko
2022-10-21 5:38 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=557d5f5d.2eed.17a56147ed0.Coremail.tumashu@163.com \
--to=tumashu@163.com \
--cc=emacs-orgmode@gnu.org \
--cc=jamshark70@zoho.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.