3

I want to display multiple figures next to each other like in this. Every image has its own source so I want to mention this in the caption.

For this I want to add the source of a figure in the caption with [@testQuelle] but it just shows the text [@testQuelle] under the picture. What am I doing wrong?

When I try to cite my source outside the figure context it just works fine so my bib is fine (see the code)

---
header-includes: |
    \usepackage{graphicx}
    \usepackage{caption}
    \usepackage{subcaption}
---
nach [@testQuelle] ist es..
\begin{figure} 
    \centering
    \caption{myCaption [@ref] }
    \label{fig:myLabel} 
\end{figure}
@online{testQuelle,
  langid = {german},
  title = {eine Test Quelle aus dem Internet},
  url = {https://testQuelle.de},
  abstract = {diese Quelle enthält viele tolle Daten},
  journaltitle = {Quelle},
  urldate = {2019-06-05},
}
#!/bin/sh
PATH=$PATH:/home/moritz/.cabal/bin/ pandoc --filter pandoc-citeproc --bibliography quellen.bib --csl=styles/din1505.csl --filter pandoc-include-code -V hyphens=URL -V breakurl -V papersize=a4paper --from=markdown --output=text.pdf  text.md \
--template template 

2 Answers2

3

You should use pandoc markdown to create the figure instead of raw TeX, as the contents of raw TeX are not processed by the pandoc-citeproc filter AFAIK.

![myCaption [@ref]](image.png){#fig:myLabel}
mb21
  • 34,845
  • 8
  • 116
  • 142
  • Thats the way I do it normally but in this case I need to display two or more figures next to each other in one line which does not work with pandoc the way I want. So I have to use raw tex I guess – Moritz Vierneusel Jul 24 '19 at 08:08
  • Then you should update the question to reflect that. Probably you can include some LaTeX in the `header-includes` or wrap the markdown figure in a markdown div and use a pandoc filter... – mb21 Jul 24 '19 at 08:49
  • I have changed the question and linked the post what I want to do exactly – Moritz Vierneusel Jul 24 '19 at 09:33
3

The main issue is that pandoc recognizes the figure statement as raw LaTeX. This means all contained Markdown expressions, like myCaption [@ref], cannot be recognized as such and will be treated as LaTeX.

The way around this is to be more explicit about what's raw LaTeX, and what's Markdown. This is possible by using generic raw attributes (requires pandoc version 2 or newer):

```{=latex}
\begin{figure} 
    \centering
```

`\caption{`{=latex}myCaption [@ref]`}`{=latex}

```{=latex}
    \label{fig:myLabel} 
\end{figure}
```
tarleb
  • 19,863
  • 4
  • 51
  • 80
  • it is working now thanks a lot, but the formatting is a pain. maybe there is a way to write a macro or function for that. thanks a lot again this helps for now – Moritz Vierneusel Jul 24 '19 at 12:03
  • Would be doable with a [Lua filter](https://pandoc.org/lua-filters.html). Best to ask a new question for that. – tarleb Jul 24 '19 at 12:10