如何使用pandoc在markdown中引用数字?

Rom*_*iel 95 markdown latex cross-reference figure pandoc

我目前正在写下markdown的文档,我想从我的文本中引用一个图像.

this is my text, I want a reference to my image1 [here]. blablabla

![image1](img/image1.png)
Run Code Online (Sandbox Code Playgroud)

我想做那个参考,因为在将我的降价转换为pdf之后,图像会放在一页或两页之后,文档没有任何意义.

更新:

我试过瑞安的回答这个职位,我不能让它工作.显然代码:

[image]: image.png "Image Title" 
![Alt text][image] 
A reference to the [image](#image).
Run Code Online (Sandbox Code Playgroud)

应该产生:

\begin{figure}[htbp] 
\centering 
\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{i mage.png} 
\caption{Alt text} 
\label{image} 
\end{figure} 

A reference to the image (\autoref{image}).
Run Code Online (Sandbox Code Playgroud)

相反,我获得:

\begin{figure}[htbp]
\centering
\includegraphics{image.png}
\caption{Alt text}
\end{figure}

A reference to the \href{\#image}{image}.
Run Code Online (Sandbox Code Playgroud)

我注意到两个问题:

  • \label{image} 没有出现:没有创建引用.
  • (\autoref{image})变为\href{\#image}{image}:未检测到交叉引用.

然后,当我将其转换为pdf时,它显然没有链接到图像.有一个链接,但它没有链接到任何东西.

任何帮助将非常感激!!

小智 89

在pandoc中你甚至可以这样做:

![This is the caption\label{mylabel}](/url/of/image.png)
See figure \ref{mylabel}.
Run Code Online (Sandbox Code Playgroud)

  • 这仅在您转换为TeX时有用,但如果您还想从同一Markdown源创建HTML则不会. (40认同)
  • 有几个过滤器可用于使图形参考适用于所有输出格式[pandoc-fignos](https://github.com/tomduck/pandoc-fignos)和[pandoc-crossref](https://github.com/lierdakil/pandoc-交叉引用) (12认同)
  • 可以使用以下方法设置宽度和高度:`![This is the caption\label{mylabel}](/url/of/image.png){width=30px height=20px}` (2认同)

tjd*_*tjd 20

您可以使用pandoc-fignos过滤器进行图形编号和参考.它适用于任何输出格式 - 不仅仅是LaTeX.

为图像的属性添加标签,如下所示:

 ![Caption.](image.png) {#fig:description}
Run Code Online (Sandbox Code Playgroud)

...然后像这样引用这个数字:

 @fig:description
Run Code Online (Sandbox Code Playgroud)

有关如何安装和应用pandoc-fignos过滤器的信息,请参见其网页.还有pandoc-eqnos过滤器用于使用方程做同样的事情.


Rom*_*iel 18

在一篇类似的帖子中读完答案之后,我和Ryan Gray聊了聊.实际上他使用的解决方案:

[image]: image.png "Image Title" 
![Alt text][image] 
A reference to the [image](#image).
Run Code Online (Sandbox Code Playgroud)

仅在使用多标记时进行调整.

说到pandoc,进行交叉引用的唯一解决方案是直接使用latex关键字:

[image]: image.png "Image Title"
![Alt text \label{mylabel}][image]
See figure \ref{mylabel}.
Run Code Online (Sandbox Code Playgroud)

  • 但正如Jakob在接受的答案中所说的那样,"这只有在你转换为TeX时才有用,但如果你也想从同一Markdown源创建HTML则不行." (5认同)

ivo*_*ron 6

Pandoc 支持引用节(通过前缀为 的节标识符#)。

关于此开放问题的评论描述了以下解决方法如何利用部分标识符在 LaTeX 和 HTML 中生成图像引用:

<div id="fig:lalune">
![A voyage to the moon\label{fig:lalune}](lalune.jpg)

</div>

[The voyage to the moon](#fig:lalune).
Run Code Online (Sandbox Code Playgroud)

前面的空行</div>是必需的。

  • 一个正确的解决方案,即[扩展 pandoc markdown 语法以允许图片标识符](https://github.com/jgm/pandoc/issues/261#issuecomment-50236381) 现在终于正在进行中。敬请关注 :) (4认同)

joe*_*lom 6

使用pandoc-crossref,您可以使用以下语法交叉引用图:

![Caption](file.ext){#fig:label}
Run Code Online (Sandbox Code Playgroud)

然后引用文本中类似于引用语法的图[@fig:label]并使用它进行编译--filter pandoc-crossref(如果您也使用它,则需要在前面--filter pandoc-citeproc)。

\usepackage[font=small,labelfont=bf]{caption}您可以使用例如in控制样式header-includes


\listoffigures如果您在 Latex 中使用,一个巧妙的相关技巧是lua-filter,它允许您设置一个短标题,而不是让整个图形图例显示在图形列表中:

![Caption](file.ext){#fig:label short-caption='my short caption'}
Run Code Online (Sandbox Code Playgroud)

然后用 进行编译--lua-filter short-captions.lua