Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use [@ref] in a figure context in latex?

Tags:

latex

pandoc

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 

like image 530
Moritz Vierneusel Avatar asked Dec 07 '25 14:12

Moritz Vierneusel


1 Answers

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}
```
like image 99
tarleb Avatar answered Dec 09 '25 19:12

tarleb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!