如何在组织模式下将单词的一部分加粗

发布于 2024-07-30 02:49:52 字数 203 浏览 3 评论 0原文

如何使 org-mode 标记适用于单词的一部分? 例如,我希望它适用于这样的情况:

=Class=es

和这样:

/Method/s

根据我的测试,org-mode 标记语法似乎仅适用于完整的单词。

How can I make org-mode markup work for a part of a word? For example, I'd like it to work for cases like this:

=Class=es

and this:

/Method/s

Based on my tests it seems like org-mode markup syntax works on complete words only.

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

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

发布评论

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

评论(7

错々过的事 2024-08-06 02:49:53

正如所提到的接受的答案,对于当前版本的 Orgmode 似乎不可能做到这一点,但这里提供了一种解决方法,因此非常接近“仅强调单词的一部分”:

(*Class*)es

(*Method*)s

As the accepted answer mentioned, it seems impossible to do this for current version of Orgmode, but here provides a workaround, so that very close to "emphasizing just parts of a word":

(*Class*)es

(*Method*)s
萤火眠眠 2024-08-06 02:49:52

如今,有一种方法可以做到这一点(不使用带引号的 HTML 标签):

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

解释

manualorg-emphasis-regexp-components 可用于

微调标记字符之前和之后允许使用的字符[...]。

这是一个包含五个条目的列表。 第一个条目列出了允许紧接在标记字符之前的字符,第二个条目列出了允许在标记字符之后的字符。 默认情况下,这些条目中都不包含字母。 因此,为了成功地将格式应用于紧邻字母之前或之后的字符串,我们必须添加 [:alpha:] (其中 匹配任何字母)到两个条目。

这就是调用 setcar 所做的事情。 第三行的目的是根据org-emphasis-regexp-components的修改版本重建强调的正则表达式。

These days, there is a way to do this (without using quoted HTML tags):

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

风和你 2024-08-06 02:49:52

我不认为你可以这样做,以便它在缓冲区中显示为粗体。 如果您只是需要它以便在导出为 html 时显示为粗体,您可以使用:

th@<b>is is ha@</b>lf bold

请参阅 引用 HTML 标签

I don't think you can do it so that it shows up in the buffer as bold. If you just need it so that it appears bold when you export it to html, you can use:

th@<b>is is ha@</b>lf bold

See Quoting HTML tags

苄①跕圉湢 2024-08-06 02:49:52

尚未提及的解决方案是在单词的所需粗体和非粗体部分之间使用 unicode 零宽度空格 (U+200B)。

要获得所需的“Classes”一词的粗体:

  1. 在缓冲区中键入“Class*es”(不带引号)。
  2. 将光标移动到“*”和“e”字符之间。
  3. 按 Cx 8 RET(执行 insert-char 命令)。
  4. 输入“零宽度空格”(不带引号)并按 RET。
  5. 将光标移动到单词的开头并插入“*”字符。

“Classes”一词现在应该具有所需的外观。

请注意,这可能会在导出时引起问题。

A solution that has not been mentioned is to use a unicode zero width space (U+200B) in between the desired bolded and unbolded parts of a word.

To get the desired bolding of the word "Classes":

  1. Type 'Class*es' in the buffer (without quotes).
  2. Move the cursor between the '*' and 'e' characters.
  3. Press C-x 8 RET (to execute the insert-char command).
  4. Type 'zero width space' (without quotes) and press RET.
  5. Move the cursor to the beginning of the word and insert a '*' character.

The word "Classes" should now have the desired appearance.

Note that there is the possibility that this will cause problems when exporting.

不甘平庸 2024-08-06 02:49:52

不,你不能那样做。 我之前搜索过相同的解决方案,但一无所获。 一个(非常)糟糕的黑客是做类似 *Class* es (带有空格)的事情。

也许您可以给创建者 Carsten Dominik (主页) 写一条短信,然后向他寻求解决方案。 他看起来是个好人。

No, you can't do that. I searched for the same solution before and found nothing. A (very) bad hack is to do something like *Class* es (with a whitespace).

Perhaps you can write a short message to the creator, Carsten Dominik (Homepage), and ask him for a solution. He seems to be a nice guy.

旧人 2024-08-06 02:49:52
src_latex{\textbf{Class}es and \textit{Method}s}
src_latex{\textbf{Class}es and \textit{Method}s}
远山浅 2024-08-06 02:49:52

之前的优秀答案的基础上,

我必须对其进行一些修改才能使其与 spacemacs 一起使用。 事实上,从 spacamacs org-layer 文档中,可以在此处获取,我们可以读

由于自动加载,调用组织函数将触发
加载 emacs 附带的 org 会引发冲突。
避免冲突的一种方法是将您的组织配置代码包装在
with-eval-after-load 块 [...]

因此,我将以下行放入我的 dotspacemacs/user-config ()

(eval-after-load "org"                                                                                                                                                 
  '(progn                                                                                                                                                              
     (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)                                                                                  
  )) 

Building up on the previous excellent answer

I had to modify it a bit in order to make it work with spacemacs. Indeed, from the spacamacs org-layer documentation, available here, we can read

Because of autoloading, calling to org functions will trigger the
loading up of the org shipped with emacs which will induce conflicts.
One way to avoid conflict is to wrap your org config code in a
with-eval-after-load block [...]

So, I put the following lines inside my dotspacemacs/user-config ()

(eval-after-load "org"                                                                                                                                                 
  '(progn                                                                                                                                                              
     (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)                                                                                  
  )) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文