6

I am trying to change the style of block quote formatting in org-mode export to PDF via LaTeX.

Using this answer, I defined a new LaTeX environment called fancyquotes. I am successfully able to create block quotes with this styling by creating a special block:

#+BEGIN_fancyquotes
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. ---Douglas Adams
#+END_fancyquotes

This successfully creates the desired TeX output:

\begin{fancyquotes}
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. ---Douglas Adams
\end{fancyquotes}

However, for compatibility with org-mode export to HTML, I would prefer to use not a special block, but rather standard quote blocks:

#+BEGIN_QUOTE
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. ---Douglas Adams
#+END_QUOTE

The problem is that, by default, the above gets exported using the quote label:

\begin{quote}
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. ---Douglas Adams
\end{quote}

How do I direct org-mode to automatically export standard quote blocks to my newly defined new LaTeX environment and apply the labels \begin{fancyquotes} and \end{fancyquotes}? In other words, how do I redefine org-mode quote blocks in LaTeX export, changing it from the default label quote to the label fancyquotes?

Bonus question: For the fancyquotes LaTeX environment I defined, how do I specify the shadequoteauthor in my org-mode source?)

2 Answers 2

6

Interesting question. I put together this start based on this part of the manual. How you set this up will depend on how you want to use it. Based on my experiments, it seems easier to define a new exporter, like the manual suggests, than it is to redefine the latex one.

(defun my-org-latex-quote-block (quote-block contents info)
  "Transcode a QUOTE-BLOCK element from Org to LaTeX.
CONTENTS holds the contents of the block.  INFO is a plist
holding contextual information."
  (org-latex--wrap-label
   quote-block
   (format "\\begin{fancyquotes}\n%s\\end{fancyquotes}" contents) info))

(org-export-define-derived-backend 'my-latex 'latex
  :translate-alist '((quote-block . my-org-latex-quote-block)))

You can then test the export with

(org-export-to-buffer 'my-latex "*Org MY-LATEX Export Results*")

This only does a dump to a buffer, but illustrates the basic idea.

Update:

I initially thought just redefining org-latex-quote-block should work, but it wasn't for me. I know why now. I have org set up to use async by default, which runs a separate emacs process with the default versions of the org functions. Turning off async makes this work too. To use this with async you would have to redefine the function in your org-export-async-init-file.

(defun org-latex-quote-block (quote-block contents info)
  "Transcode a QUOTE-BLOCK element from Org to LaTeX.
    CONTENTS holds the contents of the block.  INFO is a plist
    holding contextual information."
  (org-latex--wrap-label
   quote-block
   (format "\\begin{fancyquotes}\n%s\\end{fancyquotes}" contents) info))
2

@justbur's answer works but he forgot to add info at the end.

(defun org-latex-quote-block (quote-block contents info)
  "Transcode a QUOTE-BLOCK element from Org to LaTeX.
    CONTENTS holds the contents of the block.  INFO is a plist
    holding contextual information."
  (org-latex--wrap-label
   quote-block
   (format "\\begin{fancyquotes}\n%s\\end{fancyquotes}" contents) info))
1
  • You probably should have submitted an edit to fix the other answer, rather than providing your own (although I'm not sure about the reputation required to do that). In any case, I edited the other answer and fixed it: thanks for pointing it out!
    – NickD
    Nov 16, 2021 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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