How to make part of a word bold in org-mode
Asked Answered
C

7

28

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.

Carley answered 2/8, 2009 at 5:41 Comment(2)
Related: How can I emphasize or verbatim quote a comma in org mode?Latinist
If exporting to PDF, via LaTeX, it is possible to simply use the LaTeX solution directly in the org buffer. E.g. \textbf{V}alence \texttt{Aware} Dictionary Will print ony the "V" in bold-face, and the entire word "Aware" will appear in the org =verbatim= style.Normalcy
C
7

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

Calyptra answered 2/8, 2009 at 7:26 Comment(3)
After reading bvk's reply mentioning a mailing list thread, I tracked down the thread, and thought to include a link to the developer's response. How to make part of a word bold in org-mode.Watchband
In recent versions of org-mode, the syntax for quoting HTML strings has changed. To get th<b>is is ha</b>lf bold you'll have to write th@@html:<b>@@is is ha@@html:</b>@@lf bold.Latinist
@itsjeyd's comment's solution worked for me in GNU Emacs 25.2.2.Nauplius
L
39

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.

Latinist answered 2/7, 2014 at 20:41 Comment(6)
Nice! And, for the pedantic CL lovers out there, it also works to setf the car and cadr of org-emphasis-regexp-components.Kerwinn
...and the call to org-set-emph-re affects not only bold (* *), but also italics (/ /), underline (_ _), and strikethrough (+ +). Super nice!Kerwinn
@Kerwinn Thanks! And yes, it is supposed to be a generic solution. Too bad nobody has asked a generic question about it yet ;)Latinist
@Latinist Nice solution! Not sure why, but I have a visual issue with it: subscripts of LaTeX code enable underline fontification in org-mode. i.e. in the following LaTeX fragment (\bigcup_{i=1} F_i), "{i=1} F" is underlined in org-mode buffer. This doesn't affect the output pdf anyway.Virulent
Unfortunately this does not work if one emph follows another emph This does not work: HiDPI: *Hi*gh *D*ots *P*er *I*nch results in High Dots Per Inch where only the first and the last * is matched.. org-mode version 9.5Lalonde
@Lalonde You may find useful the answer to my question here emacs.stackexchange.com/questions/72514/…Included
C
7

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

Calyptra answered 2/8, 2009 at 7:26 Comment(3)
After reading bvk's reply mentioning a mailing list thread, I tracked down the thread, and thought to include a link to the developer's response. How to make part of a word bold in org-mode.Watchband
In recent versions of org-mode, the syntax for quoting HTML strings has changed. To get th<b>is is ha</b>lf bold you'll have to write th@@html:<b>@@is is ha@@html:</b>@@lf bold.Latinist
@itsjeyd's comment's solution worked for me in GNU Emacs 25.2.2.Nauplius
B
6

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.

Bustard answered 25/1, 2021 at 1:32 Comment(0)
M
4

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.

Mochun answered 3/8, 2009 at 10:42 Comment(2)
I just mailed into org-mode mailing list.Carley
@MichaelPaulukonis In case you are still interested, recent versions of org-mode can be customized to apply markup to parts of words. See my answer below.Latinist
R
0
src_latex{\textbf{Class}es and \textit{Method}s}
Rheumy answered 1/2, 2021 at 3:1 Comment(1)
Not a great solution if you want to export to HTML.Dividend
H
0

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)                                                                                  
  )) 
Honniball answered 16/11, 2022 at 10:29 Comment(0)
C
0

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
Carrollcarronade answered 4/7, 2023 at 15:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.