How to export inline quotations from emacs org mode to latex csquotes syntax? - emacs

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}

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

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}

Related

Emacs org-mode latex export doesnt export bibliography

I tried to export a document with orgmode to a pdf. Unfortunately it doesnt export the citations. I make a minimal example of and export it. Same Problem. So maybe i think there is a Problem with the \printbibliography.
org file
# Latexheader
#+LATEX_HEADER: \documentclass[12pt]{article}
#+LATEX_HEADER: \usepackage[a4paper, left=4cm, right=2cm, top=3cm, bottom=3cm,margin=2cm]{geometry}
#+LATEX_HEADER: \usepackage{biblatex}
# Bibliography
#+bibliography: ../lit.bib
#+cite_export: csl <PATH>/ieee.csl
# Document
* Heading
Test [cite:#all]
#+print_bibliography:
lit.bib
#inproceedings{all,
title={papertitle},
author={paperauthor},
booktitle={PAPER3000},
year={2002}
}
tex file
% Created 2022-09-20 Di 20:59
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{minted}
\documentclass[12pt]{article}
\usepackage[a4paper, left=4cm, right=2cm, top=3cm, bottom=3cm,margin=2cm]{geometry}
\author{xdobx}
\date{\today}
\title{}
\hypersetup{
pdfauthor={xdobx},
pdftitle={},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 28.1 (Org mode 9.5.2)},
pdflang={English}}
\makeatletter
\newcommand{\citeprocitem}[2]{\hyper#linkstart{cite}{citeproc_bib_item_#1}#2\hyper#linkend}
\makeatother
\usepackage[notquote]{hanging}
\begin{document}
\tableofcontents
\section{Heading}
\label{sec:org89209e9}
Test TEST [1]
\printbibliography
\end{document}
The output is unsatisfying.
PDF without bibliography
I tried different ways:
wrap \printbibliography in a #+begin_latex/#+end_latex block.
install citeproc-org: but this only brought more errors
add biblatex with #+LATEX_HEADER: \usepackage{biblatex} as #samcarter_is_at_topanswers.xyz suggest
: correct export of header, but no difference in .pdf
How can i get a nice IEEE-Style formatted bibliography at the end of my document?
Edit I
rewrite \printbibliography to #+print_bibliography: and it works in the minimal example, if i tried it at the original document it only works if i don't use #+cite_export: csl <PATH>/ieee.csl.
If i use it, i get a error: unknown bibliography extension: nil
Edit II
the rewrite from Edit I works, i just forget a #+BIBLIOGRAPHY: here from citeproc-org somewhere in the big file.
The correct solution is to load \biblatex with
#+LATEX_HEADER: \usepackage{biblatex} and insert bibliography with#+print_bibliography: where you want. Correct minimal example .org :
# Latexheader
#+LATEX_HEADER: \documentclass[12pt]{article}
#+LATEX_HEADER: \usepackage[a4paper, left=4cm, right=2cm, top=3cm, bottom=3cm,margin=2cm]{geometry}
#+LATEX_HEADER: \usepackage{biblatex}
# Bibliography
#+bibliography: ../lit.bib
#+cite_export: csl <PATH>/ieee.csl
# Document
* Heading
Test [cite:#all]
#+print_bibliography:

Tikz font in beamer export

I'm exporting a presentation from an org file that includes a block of tikz code. This is my minimal working example:
#+TITLE: Beamer Question
#+AUTHOR: J. Doe
#+OPTIONS: H:2 toc:t
#+LATEX_CLASS: beamer
#+LATEX_CLASS_OPTIONS: [presentation, aspectratio=169]
#+LATEX_HEADER: \usepackage{graphicx}
#+BEAMER_THEME: Hannover
#+COLUMNS: %45ITEM %10BEAMER_ENV(Env) %10BEAMER_ACT(Act) %4BEAMER_COL(Col)
* Introduction
** Problem
*** Normal text
:PROPERTIES:
:BEAMER_col: 0.4
:END:
This is how normal text looks; with sans serif font
*** Tikz image
:PROPERTIES:
:BEAMER_col: 0.6
:END:
#+begin_src latex :file tikz.pdf :packages '(("" "tikz")) :border 1pt :results raw % Define block styles
\begin{tikzpicture}[ text/.style={text width=5cm, align=center}]
\node (n) [text] at (0,0) {But if I write text in a tikz picture, it uses the default Latex font (serif)};
\end{tikzpicture}
#+end_src
Exporting this with M-x org-beamer-export-to-pdf produces this slide:
My question is, how can I tell tikz to use the same font as the rest of the beamer presentation?
Things I've tried:
Search online. Found nothing
Export to latex file. The result is that orgmode executes the tikz code, produces a pdf (with the wrong font) and inserts the produced pdf as an image. The problem persists
EDIT: As requested, this is the latex code generated by orgmode
% Created 2020-03-29 dom. 09:45
% Intended LaTeX compiler: pdflatex
\documentclass[presentation, aspectratio=169]{beamer}
\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{graphicx}
\usetheme{Hannover}
\author{J. Doe}
\date{\today}
\title{Beamer Question}
\hypersetup{
pdfauthor={J. Doe},
pdftitle={Beamer Question},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.1 (Org mode 9.1.9)},
pdflang={English}}
\begin{document}
\maketitle
\begin{frame}{Outline}
\tableofcontents
\end{frame}
\section{Introduction}
\label{sec:org689fb7a}
\begin{frame}[label={sec:org3b759e9}]{Problem}
\begin{columns}
\begin{column}{0.4\columnwidth}
This is how normal text looks; with sans serif font
\end{column}
\begin{column}{0.6\columnwidth}
\includegraphics[width=.9\linewidth]{tikz.pdf}
\end{column}
\end{columns}
\end{frame}
\end{document}
The problem is that using a src block causes org to invoke LaTeX on that block and this does not inherit any settings from the document. What if you change begin_src...end_src to begin_export latex ... end_export?

How to export a reference to a #begin_src block to LaTeX

I'm exporting an ORG file to LaTeX with org-latex-listings set to t. The file contains some source listings, and I want to insert some references to them.
In the generated TEX file, the reference names included in \ref seems to be translated by org-mode, but the label option of \lstset is keept as is. This way, pdflatex can't find the correct reference and gives the message LaTeX Warning: There were undefined references.
Here is an example of a MWE:
#+latex_header: \usepackage{listings}
First simple java program in listing [[thesourcelisting]]
#+name: thesourcelisting
#+caption: Simple java program
#+BEGIN_SRC java
public static void main(String[] args){
System.exit(0);
}
#+END_SRC
When exported as a LaTeX file (C-c C-e l t), I got
% Created 2016-10-18 mar 14:50
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\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{listings}
\author{alvaro}
\date{\today}
\title{}
\hypersetup{
pdfauthor={alvaro},
pdftitle={},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 25.1.2 (Org mode 8.3.6)},
pdflang={English}}
\begin{document}
\tableofcontents
First simple java program in listing \ref{orgsrcblock1}
\lstset{language=java,label=thesourcelisting,caption={Simple java program},captionpos=b,numbers=none}
\begin{lstlisting}
public static void main(String[] args){
System.exit(0);
}
\end{lstlisting}
\end{document}
The original name thesourcelisting is translated to orgsrcblock1 in the \ref command, but not in the \lstset command.
I'm using GNU Emacs 25.1.2.
Try setting org-latex-prefer-user-labels to t.
The doc string of the variable says in part (do C-h v org-latex-prefer-user-labels RET to get the whole thing):
Use user-provided labels instead of internal ones when non-nil.
When this variable is non-nil, Org will use the value of
CUSTOM_ID property, NAME keyword or Org target as the key for the
\label commands generated.
By default, Org generates its own internal labels during LaTeX
export. This process ensures that the \label keys are unique
and valid, but it means the keys are not available in advance of
the export process.

Org mode weirdness with org-export-with-sub-superscripts

I got sick of adding #+OPTIONS: ^:{} to the top of all of my .org files, so I thought I'd try to get that behavior once and for all by editing my .emacs file. Based on available documentation, it seems like
(setq org-export-with-sub-superscripts "{}")
would achieve the same behavior as #+OPTIONS: ^:{}, although when I do the (setq ... thing on its own, both A_B and A_{B} are rendered as A<sub>B</sub> in the HTML output. To ensure org-export-with-sub-superscripts is the right variable, I tried
(setq org-export-with-sub-superscripts nil)
which caused A_B to be rendered as A_B and A_{B} to be rendered as A_{B}—exactly what you'd expect. I've also tried '"{}", and (setq org-use-sub-superscripts "{}") (with and without quoting "{}"), neither of which worked.
I had this problem in Org mode 7.9.3, and it's followed me to 8.2.10. Any ideas what I'm doing incorrectly?
You must write instead:
(setq org-use-sub-superscripts '{})
Another approach is to define a template based on your #+OPTIONS
example:
here I have a template file to export to HTML which contains
---- level-0-html.org--------
#+DRAWERS: HIDDEN PROPERTIES STATE CABECALHO COMENTARIOS
:CABECALHO:
# # desabilita o superscrito/subscrito | não exporta programação
#+OPTIONS: ^:nil p:nil
#+OPTIONS: tags:nil
#+STARTUP: showeverything
#+STYLE: <link rel="stylesheet" type="text/css" href="../../css/leslie.css" />
#+LANGUAGE: pt_BR
#+OPTIONS: H:2 num:t toc:f \n:nil #:t ::t |:t ^:t -:t f:t *:t <:t
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+TAGS: export(e) noexport(n)
#+LINK_UP:
#+LINK_HOME:
:END:
#+TITLE:
#+AUTHOR: Leslie H. Watter
#+EMAIL:
#+DATE:
------------------------------------------------
and in my org-file that I'll export I have:
----- presentation.org ------
#+SETUPFILE: ~/org/templates/level-0-html.org
#+TITLE: Gerência de Redes
#+AUTHOR: Leslie H. Watter
#+EMAIL: hooorayyyy # my domain .com
* Gerência de Redes
(and here goes the entire file)
------
This way I get a consistent way of exporting.
References: http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html#sec-6

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, i.e. as \enquote{text}.
When exporting to LaTeX from Org-mode quotation marks are marked up as `` and '', e.g. 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.
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.
#N.N. 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.