简体   繁体   中英

How can I use csquotes with LaTeX export in Org-mode?

When using csquotes quotation marks are added by csquotes according to context. This is done by marking up quotation with the \\enquote macro, ie as \\enquote{text} .

When exporting to LaTeX from Org-mode quotation marks are marked up as `` and '' , eg as ``text'' .

Can Org-mode export to LaTeX with quotations marked up by \\enquote ?

I found http://comments.gmane.org/gmane.emacs.orgmode/43689 where such a feature is being planned but I do not understand whether it was implemented.


On a related note there is integration of csquotes in AUCTeX . The integration is that when a document loads csquotes then " is expanded to \\enquote{ and } respectively. This is not what I am asking for but there might be bits of code that can be interested in setting up Org-mode to export quotations marked up by \\enquote .

@NN and others, the new org-mode export function in org 8.0 has a list named org-export-smart-quotes-alist . You can add the following to your init.el and it will turn regular " double quotes into enquote{} , and ' single quotes into enquote*{} .

(add-to-list 'org-export-smart-quotes-alist 
             '("am"
               (primary-opening   :utf-8 "“" :html "“" :latex "\\enquote{"  :texinfo "``")
               (primary-closing   :utf-8 "”" :html "”" :latex "}"           :texinfo "''")
               (secondary-opening :utf-8 "‘" :html "‘" :latex "\\enquote*{" :texinfo "`")
               (secondary-closing :utf-8 "’" :html "’" :latex "}"           :texinfo "'")
               (apostrophe        :utf-8 "’" :html "’")))

A word of warning: if you want this to work in your org file's language, make sure you either have org-export-default-language set to "am" (or whatever you choose to use in the above form), or you put the appropriate #+LANGUAGE: am line at the top of your org file. If you don't, the org exporter won't call the above.

Following that thread to the end and then looking at the changelog for the 7.7 (see Headline for version 7.7 ) release I find that they have added a variable org-latex-export-quotes . I'm not entirely sure how this would have to be customized, but I suspect it would have to end up something as follows:

Original (included since it only appears in 7.7 and I believe you're running 7.6):

(defcustom org-export-latex-quotes
  '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
    ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
  "Alist for quotes to use when converting english double-quotes.

The CAR of each item in this alist is the language code.
The CDR of each item in this alist is a list of three CONS:
- the first CONS defines the opening quote;
- the second CONS defines the closing quote;
- the last CONS defines single quotes.

For each item in a CONS, the first string is a regexp
for allowed characters before/after the quote, the second
string defines the replacement string for this quote."

To:

(setq org-export-latex-quotes
  '(("en" ("\\(\\s-\\|[[(]\\)\"" . "\\enquote{") ("\\(\\S-\\)\"" . "}") ("\\(\\s-\\|(\\)'" . "`"))))

I just tested this and it does perform as expected. The sample file:

* test
this is a test of "this"

exports as (preamble omitted):

\section{test}
\label{sec-1}

this is a test of \enquote{this}

I do not know if it is possible to easily add this feature within 7.6, the easier solution would likely be to upgrade. Otherwise the easier solution in 7.6 would likely be to create a custom link (see: Org Tutorials ). This would not be as fast but does provide the desired results within the features provided by 7.6.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM