五行真人
五行真人
这家伙很懒,什么也没写!

注册于 3年前

回答
2
文章
0
关注者
0

上午没仔细分析,因为你的 00001.tex 的路径和我的不一样,导致没有出现正确的结果。
刚才又按照你的思路修改了一下,修改后的代码如下:

\ExplSyntaxOn
\NewDocumentCommand\inputfiles{}{
    \int_step_inline:nnnn {1} {1} {99999}
    {
        \int_case:nnTF {\str_count:N {##1}}
        {
            {1} { \str_set:Nn \l_filename_str {daily/0000##1.tex}}
            {2} { \str_set:Nn \l_filename_str {daily/000##1.tex}}
            {3} { \str_set:Nn \l_filename_str {daily/00##1.tex}}
            {4} { \str_set:Nn \l_filename_str {daily/0##1.tex}}
            {5} { \str_set:Nn \l_filename_str {daily/##1.tex}}
        }{}{}

        \file_if_exist:nTF {\l_filename_str} {
            \include {\l_filename_str}
        } {
            \prg_break:
        }
    }
}
\ExplSyntaxOff

\inputfiles

这一解决办法从 Latex3 的特性入手,属于治本,
而单纯加 \par 的办法,仅适用于我的表格布局,换成其它内容就又不行了,属于治标。

我找到了一个办法,思路如下:

  • 在创建 label 时将文字写入 .aux 文件;
  • 使用 \nameref 命令,从 .aux 中读取文字。(原来使用 \ref 的地方换成 \nameref

具体代码为

\documentclass[UTF8, 11pt, oneside]{ctexbook}
\usepackage{amsmath}
\usepackage{hyperref}

\newtheorem{theorem}{定理}[section]
\renewcommand\thetheorem{\arabic{theorem}}
\newtheorem{corollary}{推论}[theorem]
\renewcommand\thecorollary{\arabic{corollary}}

\makeatletter
% 创建指定名字的label
% 参数1: label的id
% 参数2: label的名字
\newcommand{\namedlabel}[2]{%
  \@bsphack
  \protected@write\@auxout{}{%
    \string\newlabel{#1}{%
        {\@currentlabel}%
        {\thepage}%
        {{#2}}%\@currentlabelname
        {\@currentHref}{}%
      }%
  }%
  \@bsphack
}%
\makeatother

\newcommand{\labeltheorem}[1]{%
  \namedlabel{#1}{定理 \thetheorem}
}

\newcommand{\labelcorollary}[1]{%
  \namedlabel{#1}{定理 \thetheorem 推论 \thecorollary}
}

\begin{document}

\section{test}

\begin{theorem}\labeltheorem{th1}
  S = ah
\end{theorem}

\begin{corollary}\labelcorollary{co1}
  abcd
\end{corollary}

\begin{theorem}\label{th2}
  S = abc
\end{theorem}

\begin{equation}
    x = y  \quad \text{\nameref{co1}}
\end{equation}

\end{document}

发布
问题