0

I am trying to get some color in an example block exported to beamer by doing something like the following

#+BEGIN_EXAMPLE
case when \textcolor{red}{condition-1 then value-1}
     when condition-2 then value-2
     .
     .
     .
     when conditionn then value-n
     else value-z
 end
#+END_EXAMPLE

According to this post on the tex stackexchange site, a verbatim enironment can get color by adding the commandchars argument, i.e.

\begin{Verbatim}[commandchars=\\\{\}]
a (black)
\textcolor{red}{b} (I want this letter to be red)
\end{Verbatim}

\end{document}

Unfortunately I cannot for the life of me figure out how to get commandchars option set in the example block. I've tried adding a #+ATTR_LATEX: :options [commandchars=\\\{\}] above the example block, modifying the begin example line as #+BEGIN_EXAMPLE :options commandchars=\\\{\}, #+BEGIN_EXAMPLE :commandchars \\\{\}, and #+BEGIN_EXAMPLE :options [commandchars=\\\{\}] and none of that has worked. How should I get color in my example block. Also, is there some reading material somewhere where I can find how to properly pass options/keywords/attributes to org-mode for exporting purposes. The org mode manual hasn't exactly made a lot of sense to me.

1 Answer 1

1

This doesn't answer the question of how to add options to an example block, but I found a solution that gets me color in a verbatim block in case someone is looking to do that in the future:

#+ATTR_LATEX: :options [commandchars=\\\{\}]
#+BEGIN_Verbatim 
 when condition-1 then value-1
     when \textcolor{red}{condition-2} then value-2
     .
     .
     .
     when conditionn then value-n
     else value-z
 end
#+END_Verbatim

I believe you have to include the fancyvbr package to get this to work.

1
  • This is the best you can do (AFAIK) unless you decide to write a derived exporter: you can then make example blocks produce whatever environment you want (instead of the default verbatim). But given that a #+BEGIN_foo block is automatically exported as a \begin{foo} LaTeX environment, there is no need to bother with an example block in the first place.
    – NickD
    Jan 7 at 3:07

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.