How to escape double quote?

后端 未结 4 1410
盖世英雄少女心
盖世英雄少女心 2020-12-19 10:45

In org mode, if I want to format text a monospace verbatim, i.e. ~...~, if it is inside quotes: ~\"...\"~, it is not formatted (left as is).

<
4条回答
  •  情歌与酒
    2020-12-19 11:16

    The culprit in this case is the regular expression in org-emph-re org-verbatim-re, responsible for determining if a sequence of characters in the document is to be set verbatim or not.

    org-verbatim-re is a variable defined in `org.el'. Its value is "\([ ('\"{]\|^\)\(\([=~]\)\([^
    \n,\"']\|[^
    \n,\"'].?\(?:\n.?\)\{0,1\}[^
    \n,\"']\)\3\)\([- .,:!?;'\")}\]\|$\)"

    quotes and double quotes are explicitly forbidden inside verbatim characters =~ by

    [^ 
    \n,\"']\|[^ 
    \n,\"']
    

    I found discussions dating back 3 years comming to the conclusion that you have to tinker with this regular expression and set the variable org-emph-re/org-verbatim-re to something that matches your wishes in your emacs setup (maybe a file local variable works as well). You can experiment by excluding double quotes from the excluding character classes and outside matches as in

    "\([ ('{]\|^\)\(\([*/_=~+]\)\([^
    \n,']\|[^
    \n,'].?\(?:\n.?\)\{0,1\}[^
    \n,']\)\3\)\([- .,:!?;')}\]\|$\)"

    but looking at that regex, heaven knows what happens to complex documents -- you have to try...

    Edit: as it happens, if I evalute the following as region, quotes inside = are exported correctly, but nothing else is :-), I investigate further when I have more time.

    (setq org-emph-re "\([ ('{]\|^\)\(\([*/_=~+]\)\([^ \n,']\|[^ \n,'].?\(?:\n.?\)\{0,1\}[^ \n,']\)\3\)\([- .,:!?;')}]\|$\)")

    Edit 2:: Got it to work by changing org.el directly:

    Change the line following (defvar org-emphasis-regexp-components from '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1) to '(" \t('{" "- \t.,:!?;')}\\" " \t\r\n,'" "." 1) and recompile org then restart emacs.

    This was a defcustom prior to the 8.0 release, it isn't anymore, so you have to live with this manual modification.

    regards, Tom

提交回复
热议问题