hyperref和atveryend冲突

发布于 2021-11-09 10:18:31

自定义一个环境,自己弄计数器,希望显示效果是第x个,总y个,在本网站上抄到一段代码

\usepackage{atveryend}
\AfterLastShipout{%
  \immediate\write\@auxout
  {\string\newlabel{ProbdailyTotal}{
  {\int_use:N \g_probdaily_counter_int}{}}}
}
\int_new:N \g_probdaily_counter_int
\NewDocumentCommand{\mytest}{ +m}{
    \int_add:Nn \g_probdaily_counter_int {1}
    #1 ,test
    \end{zljbox}
}

前一半atveryend这部分是抄的,实际我不是很明白After那个后面的东西,只是替换了一下.发现的问题是这部分代码和hyperref冲突,我原来自己的包里面有两行

\RequirePackage{hyperref}
\hypersetup{colorlinks=true,linkcolor=violet}

注释掉以后前面计数器正常的,但是如果两者在一起,那么计数器无法显示总数,可以编译通过,但是显示的是“总??个”

请问能共存吗?或者有更好的方式在保留hyperref的情况下实现计数器总y个的实现

第一次提问,谢谢

查看更多

关注者
0
被浏览
875
雾月
雾月 2021-11-09
这家伙很懒,什么也没写!

使用 hyperref 宏包后,\newlabel 的第二个参数需要5个值。

\makeatletter
\bgroup\catcode`\ =9 \endlinechar=-1 % 简单模拟LaTeX3环境
\newcounter{probdaily} % \int_new:N \g_probdaily_counter_int
\AfterLastShipout{
  \immediate\write\@auxout
    {\string\newlabel{ProbdailyTotal}
      {
        {\the\c@probdaily} % \int_use:N \g_probdaily_counter_int
        {}
        {}
        {}
        {}
      }
    }
}
\egroup
\makeatother

LaTeX2e 2020-10-01 版本之后,ateveryend 宏包是不需要的,\AfterLastShipout 已原生提供。

\documentclass{article}
\usepackage{hyperref}

\makeatletter
\bgroup\catcode`\ =9 \endlinechar=-1
\newcounter{probdaily}
\AfterLastShipout{
  \immediate\write\@auxout
    {\string\newlabel{ProbdailyTotal}
      {
        {\the\c@probdaily}
        {}
        {}
        {}
        {}
      }
    }
}
\egroup
\makeatother

\begin{document}

Hello, \LaTeXe.

\stepcounter{probdaily}

\stepcounter{probdaily}

\ref{ProbdailyTotal} = 3

\stepcounter{probdaily}

\end{document}

image.png

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览