如何在tufte风格的Bookdown中使用HTML输出,使得每个章节的旁注编号都能够重新设置?

7
我正在将一个 tufte-LaTeX 书籍转换成使用 tuftemsmbstyle 包的 tufte-Bookdown。我有大量边注,并希望每章节重新开始编号,以便在书的最后不会达到400个。
我在 Bookdown 的 GitHub 中找到了这个 CSS 代码,用于对正常的 Bookdown(使用脚注/尾注)进行此操作。然而,我试图修改该代码以适应边注,但失败了。这是我当前的 CSS 添加内容,只是用 sidenotesidenote-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;
}

这种方法并不奏效,它会添加一个新的计数器,用于对每个旁注标记进行编号,且该计数器为每个标记重置,因此正文标记得到1,旁注标记得到2。 一个带有其自身旁注标记的旁注标记 我的CSS技能并不是很出色,我也不确定下一步该怎么做才能使实际标记重置?
你可以在使用了tufte/msmbstyle构建的页面中查看示例,这里可以找到旁注4,只需向下滚动一点即可。
2个回答

2
我最终支付了一些人来解决这个问题。他们编写了一些JavaScript代码来修复它。以下代码可以保存为HTML文件,并添加到书中:
includes:
  in_header: thishtmlfile.html

在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>

0

我的建议是先在Latex文件中修复它,然后再进行导入/转换

在文档的开头/导言处添加这些行,它将在每个章节开始/重置旁注计数器。

% the answer --restarting the footnote at 0
\let\oldchapter\chapter
\def\chapter{%
  \setcounter{footnote}{0}%
  \oldchapter
}

% now your doc
\begin{document}


% would have helped if you pasted some chapters or your book...
% some chapters...
\chapter{First}
\yourtext

抱歉,我可能应该直接说出来,但正如CSS标签和失败的CSS修复所暗示的那样,这与HTML Bookdown输出有关,而不是LaTeX。我还没有尝试将tufte-Bookdown转换为PDF输出,但我在LaTeX中使用documentclass tufte-book的经验表明它已经默认重新开始每个章节的旁注编号。 - NickCHK
@NickCHK,你可以为样式设置标签,但你的问题标题是“如何在tufte风格的Bookdown中在每个章节重置旁注编号?” - Transformer
同意,我应该在标题中提到HTML或CSS。对此我感到抱歉。我刚刚修改了它。 - NickCHK

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接