7

我正在使用 tufte 和 msmbstyle 包将 tufte-LaTeX 书转换为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。

4

2 回答 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>
于 2021-05-26T05:27:12.087 回答
0

我的建议是Latex先在文件中修复它,然后再 import/Convert修复它。

在文档的开头/序言添加这些行,它将在每章启动/重置旁注计数器

% 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
于 2021-05-26T06:04:22.627 回答