5

我想在 Pandoc 中为我的图像添加诸如“图 1:Blah Blah”之类的标题,并能够像查看 @Figure1 一样引用它们。我正在使用 gpp(预处理器)为我的图像添加标题并执行各种花哨的操作,例如更改大小、格式等。但是,我无法为 Figure1、Figure2 等图像实现计数器。

我在我的 gpp 脚本中定义了以下函数:

\define{\counter}{0}

\defeval{count}{\eval{\counter+ 1}

我在我的脚本中这样称呼它:\count

但是,\counter在我的 gpp 脚本中没有得到评估,我看到以下内容error: unfinished macro

我应该如何实现这个计数器?我在 gpp 中使用 -T (tex) 模式

4

3 回答 3

2

我找到了解决我的问题的部分方法。我发现使用 CSS 的 counter-increment 属性可以帮助自动编号图像,如下所示:http ://www.w3schools.com/cssref/pr_gen_counter-reset.asp

但是,问题仍然存在,每次调用我的 gpp 标签时,我都使用 gpp 来复制同一段代码。因此,计数器永远不会增加。例如:我的 gpp 代码是:

\define{\image{src}{width}{caption}{tag}}{

<div style=" margin:50px auto; text-align:center;" class="figures">
<a  href="\src" id="\tag" style="margin:0px 20px; display:inline-block; 
text-decoration:none; color:black; "><img src="\src" width="\width px" 
alt="\caption" style="padding-bottom:0.5em;"> <div> \caption </div></a></div>}

\define{\imageref{label}}{
<span style="white-space:nowrap;"><a href="#\label" style="display:inline-block">\label</a></span>
}

我的 style.css 看起来像这样:

div .figures{
counter-reset:figure;
}

a.figure-caption:before{
counter-increment:figure;
content: "Figure" counter(figure) ":";
}

因此,每次我在标签中包含图片时\image,它总是会得到计数器Figure1

于 2013-04-24T19:27:37.880 回答
1

您可以尝试使用pandoc-fignos过滤器:它会自动创建图形编号,并启用图形引用。

简而言之,您可以像这样为图像添加标签:

![Caption.](image.png) {#fig:description}

...然后像这样引用它:

@fig:description

有关安装和使用说明,请参阅 github 上的pandoc-fignos页面。还有 pandoc-eqnos 过滤器可以用方程做同样的事情。

于 2015-06-03T19:25:11.970 回答
0

没有交叉引用的多语言 CSS 编号

这是一个简单的方法,用于使用依赖于文档语言的标签进行自动 CSS 编号。这个简单的 CSS 方法不允许引用。

对于带有引用的自动编号,而不是使用pandoc-fignos套件pandoc-xnos

body {
    counter-reset: figure;
}

p.caption:before {
    counter-increment: figure;
}

p.caption:lang(en):before {
    content: 'Figure ' counter(figure) ': ';
}

p.caption:lang(nl):before {
    content: 'Figuur ' counter(figure) ': ';
}
于 2020-06-02T11:20:50.027 回答