Nic*_*CHK 7 css r-markdown tufte bookdown
我正在使用tufte和msmbstyle包将 tufte-LaTeX 书籍转换为 tufte- Bookdown。我有一大堆旁注,希望每章都重新开始编号,这样在本书结束时我不会达到 400。
我在 Bookdown GitHub 中找到了此 CSS 代码,用于使用使用脚注/尾注的常规 Bookdown 执行此操作。但是,我尝试修改代码以使用旁注的尝试失败了。这是我当前的 CSS 添加,它只需要该代码并放入sidenoteor sidenote-number(Inspect Element 建议是正确的标签)footnote原来的位置:
/* generate new footnote calls */
.sidenote-number::after {
content: counter(fn-call);
position: relative;
top: -.5em;
font-size: 85%;
line-height: 0;
vertical-align: baseline;
}
/* use a counter for footnotes numbering */
.sidenote ol {
list-style: none;
counter-reset: fn-number;
}
.sidenote li {
counter-increment: fn-number;
}
.sidenote li p:first-child::before {
content: counter(fn-number) '. ';
width: 1.5em;
float: left;
}
Run Code Online (Sandbox Code Playgroud)
这不会按预期工作,而是添加一个新计数器,为每个旁注标记编号,并为每个标记重置一个计数器,因此文本标记获得 1,旁注标记获得 2。
我的 CSS 技能并不出色,我不确定下一步是正确的。如何让实际标记重置?
您可以在此处查看使用tufte / msmbstyle 构建的页面示例;只需向下滚动一点即可找到旁注 4。
我最终花钱请人来解决这个问题。他们编写了一些 JavaScript 来修复这个问题。以下代码可以保存为 HTML 文件,并添加到书中
includes:
in_header: thishtmlfile.html
Run Code Online (Sandbox Code Playgroud)
在 YAML 中。这是 HTML/JS/Jquery 的代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
var element_label= $("label[for *= 'tufte-sn-']");
var count = $(element_label).length;
$(element_label).each(function( index ) {
//console.log( ++index + ": " + $( this ).text() );
$(this).attr('for','tufte-sn-'+ ++index);
$(this).text(index);
});
});
$(document).ready(function () {
var element_input= $("input[id *= 'tufte-sn-']");
var count = $(element_input).length;
$(element_input).each(function( index ) {
//console.log( ++index + ": " + $( this ).text() );
$(this).attr('id','tufte-sn-'+ ++index);
});
});
$(document).ready(function () {
var element_span= $("span[class *= 'sidenote-number']");
var count = $(element_span).length;
$(element_span).each(function( index ) {
//console.log( ++index + ": " + $( this ).text() );
$(this).text(++index);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)