3

I use a custom LaTeX environment that creates a quotation box on export. A sample code looks like this:

* Org-mode heading

Here is a witty quote from a witty chap:

\begin{fancyquote}

Witty quote!

\end{fancyquote}

To maintain readability of the org-file itself, I would rather use something like this:

* Org-mode heading

Here is a witty quote from a witty chap:

** Witty quote :ignore:
:LATEXENVIRONMENT:
:PREFIX: \begin{fancyquote}
:POSTFIX: \end{fancyquote}
:END:

    Witty quote!

On export the LaTeX code in PREFIX and POSTFIX is then wrapped around the content of the heading, the heading itself not being exported.

Any ideas?

2 Answers 2

7

Use special blocks:

#+begin_fancyquote
 Something very witty!
#+end_fancyquote
2
  • The # at the line start was swallowed up for the begin and end directives.
    – éric
    Commented Aug 12, 2017 at 7:16
  • I accept this as a better answer than mine, because my link solution is less useful when dealing with a lot of content within the environment. Thanks for pointing out this feature. Commented Aug 12, 2017 at 7:29
3

I. The custom link type approach

One can define a custom link type, for example latexenv with org-add-link-type that wraps a specified latex environment around the text:

  1. Definition of the new link type with a babel code block:

    #+name: latex-env
    #+begin_src emacs-lisp   
    (org-add-link-type
     "latexenv" nil
       (lambda (path desc format)
         (when(eq format 'latex)
          (format "\\begin{%s}%s\\end{%s}" path desc path))))
    #+end_src
    
  2. Use the link type with the desired LaTeX environment, for example fancyquote:

    [[latexenv:fancyquote][This text is within the environment fancyquote]]
    

II. The special block solution

As @éric pointed out in his answer, org-mode allows to use special blocks. Here is an example with a fictional environment fancyquote with parameters:

#+ATTR_LATEX: options: [Here]{There}{That}
#+begin_fancyquote 
Something witty!
#+end_fancyquote

This will export to LaTeX as:

\begin{fancyquote}[Here]{There}{That}
  Something witty!
\end{fancyquote}
2
  • 1
    The correct sintax in #+ATTR_LATEX: :options [Here]{There}{That} Commented Nov 4, 2021 at 5:36
  • correct syntax! :-) Always happens.
    – Dox
    Commented Nov 30, 2022 at 2:23

Your Answer

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

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