Is there a method to dynamically title a latex enviroment within an rmarkdown file?

Viewed 42

I am looking for a way to title latex tikz environments in the declaration of their respective blocks in my rmarkdown files. I have found several tikz tutorials that go over creating blocks from scratch in latex, but I would like to avoid redefining the environment every time I want to use it in my main markdown pages.

I am using the memoiR bookdown template in rstudio. The relevant files are the template.tex (where the environment is defined), _output.yml (where template.tex is included), index.Rmd (where header variables are set), and my content rmarkdown Rmd files (where I want to use the environment).

Relevant portion of template.tex

% Chapter Summary environment 
\usepackage[tikz]{bclogo}

% Example environment
\newenvironment{Example}
   {\begin{bclogo}[logo=\bctrombone, noborder=true, couleur=lightgray!50]     {$example$}     \parindent0pt}
   {\end{bclogo}}

The $example$ is the name of the title of the block. This is what I would like to change on a block by block basis, ideally as passing it into the creation of the block.

Relevant portion of index.Rmd yml header

--- 
title: A Title
...
# Boxes
example: An Example
chaptersummary: In a Nutshell

This sets the global variable for the title of the box. I would prefer to redefine the environment to expect a title from its declaration, but if there is an easy way to change this variable on the fly, that is also acceptable.

\renewcommand{\example} {...} does not work, as \example is undefined.

An example of current use

<!-- content.Rmd-->
## Some Chapter 
```{block, type='Example'}
See above.
```

Produces this:

enter image description here

An example of ideal use

<!-- content.Rmd-->
## Some Chapter 
```{block, type='Example', title = "Some Different Title"}
The ideal.
```

## Some Other Chapter 
```{block, type='Example', title = "Another Title"}
The ideal.
```

With the "An Example" header being replaced with "Some Different Title" and "Another Title" respectively.

My template.tex file is included into the main document via this portion of the _output.yml:

bookdown::pdf_book:
  template: latex/template.tex
  pandoc_args: --top-level-division=chapter
  includes:
    in_header: latex/preamble.tex
    ...

Is there a method to pass through a title argument like that? And if not, how should I redefine $example$ when I want to change the header of my boxes?

0 Answers
Related