0
votes

I would like to export inline quotations in an org-document to \enquote{} commands. The csquotes package then ensures French quotation marks « » are used in the resulting pdf document.

I am well aware this question has been asked before here - and that solutions have been suggested by @Jonathan Leech-Pepin and @Christophe Poile. I tried all solutions suggested, without success. I would like to avoid (1) hardcoding the correct quotation marks or (2) using the latex command in my org document. OSX 10.15.5, emacs 26.2, org 9.2.5.

Org document header:

#+Title: GS
#+AUTHOR: HDV
#+SEQ_TODO: 
#+TAGS: 
#+STARTUP: indent
#+LANGUAGE: fr
#+LaTeX_CLASS: article
#+LATEX_CLASS_OPTIONS: [a4paper,11pt,twoside]
#+LATEX_HEADER: \usepackage[utf8]{inputenc}
#+LATEX_HEADER: \usepackage{ae,lmodern}
#+LATEX_HEADER: \usepackage[french]{babel}
#+LATEX_HEADER: \usepackage[T1]{fontenc}
#+LATEX_HEADER: \usepackage{graphicx} 
#+LATEX_HEADER: \usepackage[babel=true]{csquotes} 

Exported latex preamble:

    % Created 2020-07-07 Tue 20:45
% Intended LaTeX compiler: pdflatex
\documentclass[a4paper,11pt,twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage{ae,lmodern}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx} 
\usepackage[babel=true]{csquotes} 
\author{}
\date{\today}
\title{}
\hypersetup{
 pdfauthor={},
 pdftitle={},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 26.2 (Org mode 9.2.5)}, 
 pdflang={French}}
\begin{document}
2

2 Answers

0
votes

I used to use the following code to convert @xxx@ to \hl{xxx} (using the soul LaTeX package). You might be able to adapt this to convert "xxx" to \enquote{xxx}?

** convert @highlighted@ text on export to ~\hl{highlighted}~
#+begin_src emacs-lisp
  (defun esf/latex-filter-highlight (text backend info)
    "Convert @...@ to \hl{...} in LaTeX export."
    (when (org-export-derived-backend-p backend 'latex)
      (replace-regexp-in-string "@\\([^@]+\\)@" "\\\\hl{\\1}" text)))

  (add-to-list 'org-export-filter-plain-text-functions
               'esf/latex-filter-highlight)
#+end_src 
0
votes

You do not need csquotes or \enquote{} to get guillemets; there is smart quote support out of the box in Org mode. The following suffices:

#+OPTIONS: ':t
#+LANGUAGE: fr
#+LATEX_HEADER: \usepackage[french]{babel}

* foo

As somebody once said:
  
"You cannot explain anything to a stone."

You turn on smart quotes, set the #+LANGUAGE to fr to select the french style of smart quotes and then let babel figure it out. The TeX file produced looks like this (only the significant parts are shown):

...
\usepackage[french]{babel}
...
\begin{document}

...

\section{foo}
\label{sec:orgd0ec1fc}

As somebody once said:

\og You cannot explain anything to a stone.\fg{}
\end{document}

If you really want \enquote, you can modify the value of org-export-smart-quotes-alist. I think the best way is to duplcate the current section for fr, modify it for your purposes and add it to the beginning of the alist where it is going to shadow the existing entry:

  (setq fr-quotes '("fr"
            (primary-opening :utf-8 "« " :html "« " :latex "\\enquote{" :texinfo "@guillemetleft{}@tie{}")
            (primary-closing :utf-8 " »" :html " »" :latex "}" :texinfo "@tie{}@guillemetright{}")
            (secondary-opening :utf-8 "« " :html "« " :latex "\\\enquote{" :texinfo "@guillemetleft{}@tie{}")
            (secondary-closing :utf-8 " »" :html " »" :latex "\\}" :texinfo "@tie{}@guillemetright{}")
            (apostrophe :utf-8 "’" :html "’"))

  (add-to-list 'org-export-smart-quotes-alist fr-quotes)

As you can see I changed the opening and closing quotes for LaTeX to use \enquote{ to open and } to close. Adding it to the front of the list allows you to get rid of it quickly if you want to go back to the default:

(setq org-export-smart-quotes-alist (cdr org-export-smart-quotes-alist))

gets rid of the first entry (the added "fr" entry) allowing the default "fr" entry to be seen. You should probably do C-h v org-export-smart-quotes-alist and look at its value carefully.

Then the Org mode file becomes:

#+OPTIONS: ':t
#+LANGUAGE: fr
#+LATEX_HEADER: \usepackage[french]{babel}
#+LATEX_HEADER: \usepackage[babel=true]{csquotes}

* foo

As somebody once said:
  
"You cannot explain anything to a stone."

and the resulting tex file looks like this (again, only the significant parts are shown):

...
\usepackage[french]{babel}
\usepackage[babel=true]{csquotes}
...
\begin{document}
...
\section{foo}
\label{sec:orgb8fcb36}

As somebody once said:

\enquote{You cannot explain anything to a stone.}
\end{document}