2

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?

4

Use special blocks:

#+begin_fancyquote
 Something very witty!
#+end_fancyquote
  • The # at the line start was swallowed up for the begin and end directives. – éric Aug 12 '17 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. – Singulaere Entitaet Aug 12 '17 at 7:29
1

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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