12

If I write something like *shrug* in org mode, it will be automatically fontified as bold text. How can I prevent that, i.e. actually having *shrug* appear verbatim when exported?

Edit:

I still want to be able to use bold fontification (without having to change the default star-syntax for bold text), and it should not matter to what file format my org file is exported, e.g. it should work for Markdown as well as HTML export.

This is some important stuff, that is why it is written in bold. But for something else, I have no Idea *shrug*.

  • 1
    If you are exporting this to LaTeX later, you could try \ast{}shrug\ast{} or \star{}shrug\star{}, similar, with HTML you could use entity encoding: &#2a;, or if adding spaces before or after the asterisk is an option, that would work too. – wvxvw Sep 17 '15 at 8:41
  • It seems like suvayu's answer of just wrapping it in verbatim markers is what you want. Alternatively, you could modify org-emphasis-alist so that another character is used to bold text. – user2699 Sep 17 '15 at 15:56
  • Not exactly. =*shrug*= results in the exported HTML to be wrapped in a code-tag, and in markdown has backticks. I want it to be not formatted in any way at all. – timor Sep 17 '15 at 16:08
  • Edited question to reflect that changing org-emphasis-alist is not really an option. I don't want to change everything bold that already exists in my .org file. – timor Sep 17 '15 at 16:14
  • 2
    The \ast{}shrug\ast{} mentioned by wvxvw is probably your best option. it exports to html as ∗shrug∗ and to latex as $\ast$shrug$\ast$ using the appropriate character entities. org-toggle-pretty-entities displays them as UTF8 characters in the org buffer. – mutbuerger Sep 17 '15 at 16:49
9

This answer is inspired after collective suggestions on the emacs-org-mode GNU list to use the org-entity ( C-h i g (org) Special symbols ) \ast{} instead of zero width space characters (which I suggested in my other answer here).

Below is a generic solution where the user does not need to remember the org entities for various symbols. It inserts the org entity (if available) when user does C-u SYMBOL; works for C-u *, C-u /, C-u =, etc.

(defun modi/org-entity-get-name (char)
  "Return the entity name for CHAR. For example, return \"ast\" for *."
  (let ((ll (append org-entities-user
                    org-entities))
        e name utf8)
    (catch 'break
      (while ll
        (setq e (pop ll))
        (when (not (stringp e))
          (setq utf8 (nth 6 e))
          (when (string= char utf8)
            (setq name (car e))
            (throw 'break name)))))))

(defun modi/org-insert-org-entity-maybe (&rest args)
  "When the universal prefix C-u is used before entering any character,
    insert the character's `org-entity' name if available.

    If C-u prefix is not used and if `org-entity' name is not available, the
    returned value `entity-name' will be nil."
  ;; It would be fine to use just (this-command-keys) instead of
  ;; (substring (this-command-keys) -1) below in emacs 25+.
  ;; But if the user pressed "C-u *", then
  ;;  - in emacs 24.5, (this-command-keys) would return "^U*", and
  ;;  - in emacs 25.x, (this-command-keys) would return "*".
  ;; But in both versions, (substring (this-command-keys) -1) will return
  ;; "*", which is what we want.
  ;; http://thread.gmane.org/gmane.emacs.orgmode/106974/focus=106996
  (let ((pressed-key (substring (this-command-keys) -1))
        entity-name)
    (when (and (listp args) (eq 4 (car args)))
      (setq entity-name (modi/org-entity-get-name pressed-key))
      (when entity-name
        (setq entity-name (concat "\\" entity-name "{}"))
        (insert entity-name)
        (message (concat "Inserted `org-entity' "
                         (propertize entity-name
                                     'face 'font-lock-function-name-face)
                         " for the symbol "
                         (propertize pressed-key
                                     'face 'font-lock-function-name-face)
                         "."))))
    entity-name))

;; Run `org-self-insert-command' only if `modi/org-insert-org-entity-maybe'
;; returns nil.
(advice-add 'org-self-insert-command :before-until #'modi/org-insert-org-entity-maybe)

So when the user types C-u *, \ast{} is inserted and the below message is displayed in the echo area,

Inserted ‘org-entity’ \ast{} for the symbol *.

If org-pretty-entities is set to t above, the inserted \ast{} will be displayed as *.

If an org-entity does not exist for a character X and if the user does C-u X, X is simply inserted 4 times (as C-u would usually do).

  • This looks really convenient. The one drwaback (in my opinion) that remains, is that the .org file, which does not contain any LaTeX constructs so far, now has bits of non-org-mode syntax (LaTeX) scattered throughout the file. By the way, is there a reason that no construct like \*thisisnotbold\* exists? – timor Sep 23 '15 at 7:36
  • 1
    This is org syntax too. Check out the org-entities documentation. – Kaushal Modi Sep 23 '15 at 10:17
8

Using the ZERO WIDTH SPACE unicode char

You can fail the bold emphasis parsing by adding a zero-width space character (indicated by [ZWS] in the below snippets) before the first asterisk or after the second asterisk.

Both of the below snippets exported fine to HTML in my testing:

  • [ZWS] before the first asterisk

    This is some *bold* test and this is ​[ZWS]*not bold*.
    
  • [ZWS] after the second asterisk

    This is some *bold* test and this is *not bold*​[ZWS].
    

You can enter the ZERO WIDTH SPACE (unicode name) by doing C-x 8 RET 200b RET.
I use this very often, so I have bound this to C-x 8 0.


Update

As per the discussion on the emacs-org-mode mailing list, using non-ASCII characters for escaping is not recommended; instead org-entities should be used if applicable. I too agreed with that and came up with this another solution that makes inserting org-entities really easy (C-u * in this case).

  • Technically that is a pretty quick way to solve the problem. Does it rely on org-mode not interpreting the ZWS as whitespace? Also, I fear the solution is non-obvius for other people editing the org file... – timor Sep 18 '15 at 7:43
  • @timor I have brought up this discussion on the emacs-orgmode@gnu.org mailing list. If interested, you can follow/add to the discussion here. – Kaushal Modi Sep 18 '15 at 18:47
  • @timor, it isn't obvious, but of all the solutions given here it's the only one that works without modifying emacs configuration, so it is the most obvious if you want to share your files. – user2699 Sep 22 '15 at 14:41
  • @user2699 FWIW, use of org entities in the files will work right away without any user config.. it's just the use of plain ascii \ast{} in the files. My other solution simply makes entering \ast{} faster and easier to remember. – Kaushal Modi Sep 22 '15 at 14:47
2

By verbatim, if you actually mean use some markup in the exported LaTeX, then you can just use =*shrug*=. However if you just want it to be exported as *shrug*, and you want to do this all the time, I would recommend filters. If however, you only need this for some instances of *shrug*, you should use the alternative suggested by @wvxvw. You could do this cleanly using macros. Some examples follow.

Filters

(defun my-bold (contents backend info)
  (when (org-export-derived-backend-p backend 'latex)
    (replace-regexp-in-string "\\`\\\\textbf{\\(.+\\)}"
                              "\\\\ast{}\\1\\\\ast{}" contents)))

(add-to-list 'org-export-filter-bold-functions 'my-bold)

Essentially the above filter looks for the \textbf{..} markup in the transcoded string, and replaces it with \ast{}..\ast{}, without changing whatever was wrapped inside {..}. I have not tested the regular expression and the replacement string, so there could be mistakes, but you get the idea. Similarly to cover other backends, one can include extra snippets like this:

(when (org-export-derived-backend-p backend 'latex)
   (replace-regexp-in-string "<b>\\(.+\\)</b>" "\&#2a;\\1\&#2a;" contents))

Same caveat holds for the regular expression above.

Macros

Org source:

#+macro: nobold @@latex:\ast{}$1\ast{}@@ @@html:&#2a;$1&#2a;@@

This text is *bold* this is nobold{{{not}}}

exports to LaTeX as:

This text is \textbf{bold} this is \ast{}not\ast{}

and to HTML as:

This text is <b>bold</b> this is  &#2a;not&#2a;

You can of course add as many backends as you wish to the macro.

Edit: as Kaushal points out in the comments, the export snippet for latex is optional in this case. I however prefer to use them whenever bare latex is involved, since I find it rather difficult to keep track of the list of org-entities and the specific rules behind identifying bare latex in Org source.

Note:

  • the filter examples are untested,
  • I don't know any HTML, so there might be some mistakes in the respective bits.
  • Shouldn't this macro definition suffice: #+macro: nobold \ast{}$1\ast{}? ast is one of the members of org-entities list, that specifies what the latex, html, ascii, etc exports should look like: ("ast" "\\ast" t "&lowast;" "*" "*" "*"). The order of elements in that list is "name, LaTeX replacement, LaTeX mathp, HTML replacement, ASCII replacement, Latin1 replacement, utf-8 replacement". – Kaushal Modi Sep 21 '15 at 3:21
  • @kaushalmodi Yes it would be, however since we already know it is LaTeX, there is no harm in putting it inside a latex snippet. In my experience using snippets is much more robust because of its unambiguity. – suvayu Sep 21 '15 at 9:49
-1

This is controlled by the variable org-emphasis-alist, and can be easily modified.

  • Put point over bold text, use command what-cursor-position C-u C-x = to find the face, note that it has property org-emphasis.
  • Call customize-group and search for org-emphasis
  • org-emphasis-alist should show up, with various options for marking text.
  • Delete the entry corresponding to *
  • Apply changes, and restart org-mode or emacs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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