如何在 Org 模式下制作不间断空格(连带)并正确导出到 LaTeX

发布于 2025-01-06 00:31:28 字数 1250 浏览 1 评论 0原文

在 (La)TeX 中,不间断空格称为连线,它们由 ~ 组成。例如,在缩写词之后使用连线,这样在缩写词之后就不会直接换行,并且以点结尾的缩写词不会被视为结束句子。后一种用法很重要,因为标准 LaTeX 在点后面放置的间距比单词之间的间距更长。

从 Org 模式导出到 LaTeX 时,~ 被视为显式字符,而不是平局。忽略不间断空格的使用并不是一种替代方案,因为它会导致错误的间距(请参阅上面示例中的第二句)。一种替代方法是强制 Org-mode 将 ~ 视为 LaTeX,并使用 #+BEGIN_LaTeX ~ #+END_LaTeX 但它很冗长并且导出到其他格式会中断。最后,按照 http://comments.gmane.org/gmane 中的建议,使用 UTF-8 不间断空格。 emacs.orgmode/24716 不起作用,因为 LaTeX 不将其视为空格。那么,如何在 Org 模式下使用不间断空格并正确导出到 LaTeX?

这是一个例子来澄清。第一个句子失败,因为 ~ 被视为显式字符。显然,第二句话失败了,因为最后一个点被 LaTeX 视为句子的结束。第三句话可以正确导出,但它很冗长并且会破坏导出为其他格式的效果。第四行(由 Cx 8 Space 插入的 UTF-8 不间断空格分隔)失败,因为 LaTeX 不将其视为空格:

#+title:Title

e.g.~example

e.g. example

#+BEGIN_LaTeX
e.g.~example
#+END_LaTeX

e.g. example

此导出 (Cx Ce L )到以下 LaTeX 代码:

e.g.\~{}example

e.g. example

e.g.~example

e.g. example

呈现为:

LaTeX returned

我正在运行Emacs 23.3.1 中的组织模式 7.6。

In (La)TeX non-breaking spaces are called ties and they are made by ~. Ties are for instance used after abbreviations so that there is no line break directly after them and so that dots ending abbrevations are not treated as ending sentences. The latter use is important because standardly LaTeX puts a longer space after dots than between words.

When exporting from Org-mode to LaTeX ~ is treated as an explicit character and not as a tie. Ignoring the use of non-breaking spaces is not an alternative because it leads to the wrong spacing (see the second sentence in the example above). One alternative is to force Org-mode to treat ~ as LaTeX with #+BEGIN_LaTeX ~ #+END_LaTeX but it is verbose and export to other formats breaks. Finally, using UTF-8 non-breaking spaces, as suggested in http://comments.gmane.org/gmane.emacs.orgmode/24716, does not work because LaTeX does not treat it as a space. So, how can I use non-breaking spaces in Org-mode that are properly exported to LaTeX?

Here is an example to clarify. The first sentence fails because ~ is treated as an explicit character. The second sentence fails, obviously, because the last dot is treated as ending a sentence by LaTeX. The third sentence exports properly but it is verbose and breaks export to other formats. The fourth line (separated by an UTF-8 non-breaking space which is inserted by C-x 8 Space) fails because it is not treated as a space by LaTeX:

#+title:Title

e.g.~example

e.g. example

#+BEGIN_LaTeX
e.g.~example
#+END_LaTeX

e.g. example

This exports (C-x C-e L) to the following LaTeX code:

e.g.\~{}example

e.g. example

e.g.~example

e.g. example

Which renders as:

LaTeX rendered

I am running Org-mode 7.6 in Emacs 23.3.1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

没有你我更好 2025-01-13 00:31:28

http://orgmode.org/manual/Special-symbols.html 上,我找到了双倍间距的解决方案问题:

Org

e.g.\nbsp{}example

LaTeX

e.g.~example

On http://orgmode.org/manual/Special-symbols.html I found the solution to the double spacing problem:

Org

e.g.\nbsp{}example

LaTeX

e.g.~example
葬﹪忆之殇 2025-01-13 00:31:28

所有其他答案都很好,但为了完整起见,我想提及 org-entities。更重要的是,因为您可以利用此机制进行更通用的导出自定义,并支持多个后端。

org-entities 设置为如下所示:

(setq org-entities-user
      '(("space" "~" nil " " " " " " " ")))

以下 Org 源:

E.g.\space{}a, b, c

导出为 LaTeX 为:

E.g.~a, b, c

并导出为 HTML 为:

<p>
E.g. a, b, c</p>

All the other answers work well, however I would like to mention org-entities for the sake of completeness. More so, because you can leverage this mechanism to do more generic export customisations, as well as support multiple backends.

Set org-entities to something like this:

(setq org-entities-user
      '(("space" "~" nil " " " " " " " ")))

The following Org source:

E.g.\space{}a, b, c

exports to LaTeX as:

E.g.~a, b, c

and exports to HTML as:

<p>
E.g. a, b, c</p>
一笑百媚生 2025-01-13 00:31:28

答案已在您链接的 gmane 线程中暗示。特别是 最后回复 表示使用 \nbsp 作为不间断空格。就其本身而言,这是行不通的,因为您需要在 \nbsp 之后有一个空格才能将其识别为命令,而不仅仅是文本的一部分。

但是,以下方法有效(添加到您的尝试列表中:

#+title:Title

* Test
1) e.g.~example

2) e.g. example

3) 
  #+BEGIN_LaTeX
    e.g.~example
  #+END_LaTeX

4) e.g. example

5) e.g.\nbsp example
   (non-breaking \240 space between \nbsp and example)

哪个输出到 LaTeX 为:

\item e.g.\~{}example
\item e.g. example
\item e.g.~example
\item e.g. example
\item e.g.~ example %\240 non-breaking between ~ and example

这呈现为:

Rendered


编辑

我刚刚重新测试了我的结果,不知何故,我的不间断空格第一次没有正确导出,并且我的结果发生了变化(朝着应该预期的方向而不是显示的方向),以保留历史记录并保持评论有意义

Org

#+title:Title

* Test
1) e.g.~example

2) e.g. example

3) 
  #+BEGIN_LaTeX
    e.g.~example
  #+END_LaTeX

4) e.g. example   %Space is non-breaking

5) e.g.\nbsp example    %Space is non-breaking

LaTeX

\item e.g.\~{}example
\item e.g. example
\item e.g.~example    
\item e.g. example    %Space is non-breaking
\item e.g.~ example   %Space is non-breaking

Rendered

。 src="https://i.sstatic.net/CRwp9.png" alt="在此处输入图像描述">

这对应于规定的双倍行距(以及正确导出的不间断空格)

The answer is hinted at within the gmane thread you linked. In particular the last reply says to use \nbsp as your non-breaking space. By itself this won't work since you need a space after the \nbsp for it to recognize it as a command and not just part of your text.

However the following works (adding to your list of attempts:

#+title:Title

* Test
1) e.g.~example

2) e.g. example

3) 
  #+BEGIN_LaTeX
    e.g.~example
  #+END_LaTeX

4) e.g. example

5) e.g.\nbsp example
   (non-breaking \240 space between \nbsp and example)

Which outputs to LaTeX as:

\item e.g.\~{}example
\item e.g. example
\item e.g.~example
\item e.g. example
\item e.g.~ example %\240 non-breaking between ~ and example

And this renders as:

Rendered


EDIT

I just retested my results, somehow my non-breaking spaces had not exported properly the first time and my results have changed (towards what should be expected rather than what was displayed). New results below to retain history and keep comments making sense.

Org

#+title:Title

* Test
1) e.g.~example

2) e.g. example

3) 
  #+BEGIN_LaTeX
    e.g.~example
  #+END_LaTeX

4) e.g. example   %Space is non-breaking

5) e.g.\nbsp example    %Space is non-breaking

LaTeX

\item e.g.\~{}example
\item e.g. example
\item e.g.~example    
\item e.g. example    %Space is non-breaking
\item e.g.~ example   %Space is non-breaking

Rendered

enter image description here

This corresponds to the stated double-spacing (as well as the non-breaking space exporting properly)

浅笑依然 2025-01-13 00:31:28

我在文档/模板/骨架的标题中包含以下内容:

\#+LaTeX_HEADER: \DeclareUnicodeCharacter{00A0}{~}

并且我使用 Cx 8 SPC 在文本中插入 unicode 不间断空格。这应该可以导出到 LaTeX 或 HTML。

说明:

DeclareUnicodeCharacter定义在文件utf8.definputenc用来定义utf8映射的文件)中,定义含义Unicode 字符。第一个参数是字符的十六进制代码,第二个参数是替换的 LaTeX 代码。

不间断空格是 U+00A0,因此第一个参数是 00A0。在 LaTeX 中,不间断空格是通过波浪号生成的,因此第二个参数是单个波浪号。

I included the following in the heading of my document/template/skeleton:

\#+LaTeX_HEADER: \DeclareUnicodeCharacter{00A0}{~}

And I use C-x 8 SPC to insert the unicode non-breaking space in the text. This should work exporting to LaTeX or to HTML.

Explanation:

The macro DeclareUnicodeCharacter is defined in the file utf8.def (the file used by inputenc to define the utf8 mapping) to define the meaning of Unicode characters. The first argument is the hexadecimal code for the character, and the second is the replacement LaTeX code.

The non breaking space is U+00A0, therefore the first argument is 00A0. In LaTeX, a non-breaking space is generated with a tilde, therefore the second argument is a single tilde.

╰◇生如夏花灿烂 2025-01-13 00:31:28

我认为最好的方法之一是@@latex:eg~example@@,嵌入内联乳胶代码以进行导出。

I think one of the best ways is @@latex:e.g.~example@@, embedding inline latex code for exporting.

守护在此方 2025-01-13 00:31:28

对于那些仍在寻求有关该问题的建议并且不希望文本中出现 \nbsp 或 \space 等乳胶风格麻烦的人,我将添加我的解决方案。

我将 unbreakable space (U+00A0) 和 thin unbreakable space (U+202F) 作为 Unicode 字形插入,并在我的 emacs 中将它们设置为方便的快捷方式init.el (对我来说很方便,也就是说,那些来自我的 OpenOffice 岁月):

(global-set-key [?\C-\S-\ ] [?\x00A0])
(global-set-key [?\C-\ ] [?\x202F])

字形显示为微小且正常的细彩色下划线宽度分别。这些文字很容易让人看懂。

Org 的导出过滤器按原样导出这些字形,因此我必须通过

sed --in-place \
    -e 's/ /\\:/g' \
    -e 's/ /\\,/g' \
mytexsource.tex

sed 表达式中的那些空格来过滤生成的 TeX 源,这些空格是字形 160 (00A0h) 和 8239 (202Fh),分别。

无可否认,该解决方案使用了额外的处理阶段,我想这可以通过 Org 的过滤器来弥补。

另一方面,它在 Org/emacs 中看起来又漂亮又容易。

顺便问一下,波浪线在乳胶中不是一个易碎的空格吗?

For those still searching for advice on that issue and not wishing latex-style botherations like \nbsp or \space in their texts, I'll add my solution.

I'm inserting unbreakable space (U+00A0) and thin unbreakable space (U+202F) as Unicode glyphs, having them set to handy shortcuts in my emacs's init.el (handy to me, that is; those come from my OpenOffice years):

(global-set-key [?\C-\S-\ ] [?\x00A0])
(global-set-key [?\C-\ ] [?\x202F])

The glyphs are displayed as thin colored underscores of tiny and normal width respectively. The text is easy on eyes with those.

The Org's export filter exports those glyphs as they are, so I have to filter the resulting TeX source through

sed --in-place \
    -e 's/ /\\:/g' \
    -e 's/ /\\,/g' \
mytexsource.tex

Those spaces in sed's expressions are glyphs 160 (00A0h) and 8239 (202Fh), respectively.

The solution admittedly uses extra processing stage, which, I imagine, could be possibly remedied by Org's filters.

On the other hand it looks nice and easy on eyes in Org/emacs.

By the way, isn't tilde a breakable space in latex?

倾听心声的旋律 2025-01-13 00:31:28

使用 Cx 8 SPC 输入不间断空格会将不间断空格导出到 LaTeX 以及我的 Emacs 29.4 和 Org-mode 9.6.15 中的 PDF。

Entering a non-breaking space with C-x 8 SPC exports a non-breaking space to LaTeX and the PDF in my Emacs 29.4 with Org-mode 9.6.15.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文