Sagittarius Rover
Sagittarius Rover
我要成为Typst糕手/(ㄒoㄒ)/~~

注册于 2年前

回答
266
文章
0
关注者
11

代码可以更短,MWE也应该更短!!!

image.png

正常情况下,#2不需要显式写入\newenvironment的定义中<begin-def>的部分,对于:

\begin{env}
<something>
\end{env}

LaTeX会自动把<something>自动插入到<begin-def><end-def>之间。

区别下面的例子:

\documentclass{article}
\usepackage{tcolorbox}
\newenvironment{tcbA}[2][]{%
\begin{tcolorbox}[#1]
    #2
}{\end{tcolorbox}}
\newenvironment{tcbB}[1][]{%
\begin{tcolorbox}[#1]
}{\end{tcolorbox}}
\begin{document}
    \begin{tcbA}
        Hello, \LaTeX !
    \end{tcbA}
    
    \begin{tcbB}
        Hello, \LaTeX !
    \end{tcbB}
\end{document}

在你的MWE中,因为#2是必须参数,因此\begin{tcbA}在处理时,第一个参数optional argument未指定,所以为默认的<empty>;但是第二个参数mandatory argument缺失,所以TeX先自动吞下(swallow)了一个token H.在<begin-def>命令结束后,之后再把ello, \LaTeX{}的内容作为<something>放进tcb内部。

\fancyhead[CO]{\zihao{5}\rightmark}替换为\fancyhead[CO]{\zihao{5}\makebox[6\ccwd][s]{\rightmark}}

另外你似乎多删除了hyperref宏包的调用。或许可以试试这个:

\documentclass[b5paper,twoside,openany,UTF8]{ctexbook}
\usepackage{fancyhdr}
\usepackage{hyperref}%

\pagestyle{fancy}
\fancyhf{}
\fancyhead[CO]{\zihao{5}\rightmark}
\fancyhead[CE]{\zihao{5}\leftmark}
\fancyfoot[RO,LE]{--~\thepage~--}
\renewcommand{\headrulewidth}{0.5pt} 
\renewcommand{\chaptermark}[1]{%
    \markboth{\texorpdfstring{\makebox[5\ccwd][s]{第\zhnumber{\thechapter}回}}{第\zhnumber{\thechapter}回}}{#1}
}

\fancypagestyle{plain}{%
    \fancyhf{} % 清空页眉页脚
    % 偶数页左下角、奇数页右下角显示页码
    \fancyfoot[RO,LE]{--~\thepage~--}
    \renewcommand{\headrulewidth}{0pt} % 去掉页眉横线
}

\fancypagestyle{frontmatter}{ %frontmatter部分的页眉页脚定制
    \pagestyle{plain} 
    \fancyhf{} 
    \fancyhead[CO]{\zihao{5}\makebox[6\ccwd][s]{\rightmark}}
    \fancyhead[CE]{\zihao{5}\makebox[6\ccwd][s]{这是一本书}}
    \renewcommand{\headrulewidth}{0.5pt} % 确保页眉横线宽度为0.5pt
    \fancyfoot[LE,RO]{--~\thepage~--}  %奇数页右下角、偶数页左下角显示页码
}

\begin{document}
    
    \frontmatter%
    \pagestyle{frontmatter} 
    \pagenumbering{roman}
    \tableofcontents %生成目录

    \mainmatter% 我认为作为一本完整的书
    % \frontmatter \mainmatter \backmatter总是要用好的
    \pagestyle{fancy}
    
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}    
\end{document}

image.png


BTW,如果追求代码更简洁的话,也许可以把\fancypagestyle缩短,让他继承自plain样式:

\fancypagestyle{frontmatter}[plain]{%frontmatter部分的页眉页脚定制
    \fancyhead[CO]{\zihao{5}\makebox[6\ccwd][s]{\rightmark}}
    \fancyhead[CE]{\zihao{5}\makebox[6\ccwd][s]{这是一本书}}
    \renewcommand{\headrulewidth}{0.5pt} % 确保页眉横线宽度为0.5pt
}

image.png

避免题文不符。

\usepackage{ctex}调用宏包提供中文支持
\documentclass{ctexart}声明文档类,其内部调用了ctex宏包

上面两者是不一样的。

image.png

从这个截图来看,你应该没有指定这个编辑器的编译引擎

ctex宏包或者ctexart文档类均需要xelatex或者lualatex引擎支持。更具体的可见lshort-zh-cn第二章。

考古...

参考自QQ群里Eureka老师给的回答,请看下面的对比。

当然,OP原问题给的代码过长了,提问应该尽量保证代码“最简短”,避免增加阅读障碍。
输出latex3变量和计数器问题显然应该另开两个问题,这样很容易让后来的读者感到混乱迷惑,削弱论坛的信息共享作用。

可以比较下面的例子:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{counter}
\newcounter{cntA}
\newcounter{cntB}
\NewExpandableDocumentCommand{\cmdA}{}
{%
    \thecntA%
    \addtocounter{cntA}{1}
}
\NewExpandableDocumentCommand{\cmda}{}
{%
   okA&\cmdA\\
}
\newcommand{\cmdB}{%
    \thecntB%
    \addtocounter{cntB}{1}
}
\newcommand*{\cmdb}{%
    okB&\cmdB\\
}
\setlength{\parindent}{0pt}
\begin{document}

\begin{tblr}[expand=\expanded]{colspec={|X|X|}}
    \expanded{\cmda}
    \expanded{\cmda}
    \expanded{\cmda}
\end{tblr}

\bigskip

\begin{tblr}[expand=\cmdb]{colspec={|X|X|}}
    \cmdb
    \cmdb
    \cmdb
\end{tblr}
\end{document}

image.png

tblr以及longtblr环境中,有两种展开方式:

  • 直接使用expand=<expandable token>,将直接展开一次
  • 如果使用expand=\expanded后在tblr内部使用\expanded{<expandable token>}进行完全(exhaustive)展开(e-type展开)

而虽然\newcommand\NewExpandableDocumentCommand定义的命令均可展开,但:

  • \newcommand允许只执行部分展开
  • \NewExpandableDocumentCommand要求只能被完全展开

而同时\addtocounter实际上是TeX原语\advance\value{cnt}+1:

\addtocounter: 
macro:#1#2->\@ifundefined {c@#1}{\@nocounterr {#1}}{\global \advance \csname c@#1\endcsname #2\relax }

这是一种assignment过程,属于不可展开的命令,他们因此不应该被放在\NewExpandableDocumentCommand内部。若如此做,将导致该命令变为不可展开类型。

因此在OP的原问题中,tblr环境将会先搜集其内部的所有命令,然后再执行展开\NewExpandableDocumentCommand定义的\cmd(但此时不可展开)。此时使用\expanded{\cmd}将导致直接进行e-type展开将\thecnt完全展开为初始值0.

因此洞察到\addtocounter不可展开,同时在这一情形下仅需要单步展开,决定了应该使用\newcommand以及\expand=\cmd实现.

@u38442 林间花(xxn)老师指出:

你好像传入了这个 \makebox[5\ccwd][s]{第\chinese{chapter}回} 就变成了 [5][s]第一回....
书签使用 \texorpdfstring{⟨TEX 字符串⟩}{⟨PDF 字符串⟩}
同时严厉地指责了我不看hyperref文档的恶劣行为:
image.png

尝试传入chapter/number={\texorpdfstring{...}{...}}即可:

\documentclass[b5paper,twoside,openany]{ctexbook}
\usepackage{zhlipsum}
\ctexset{
    chapter/name = {,},
    chapter/number = {\texorpdfstring{\makebox[5\ccwd][s]{第\chinese{chapter}回}}{第\chinese{chapter}回}},
}
\usepackage[%
    bookmarksnumbered=true,
]{hyperref}
\begin{document}
    \tableofcontents
    \chapter{这是一个标题名1}\zhlipsum[1-6]
    \addtocounter{chapter}{9}
    \chapter{这是一个标题名2}\zhlipsum[1-6]
\end{document}

image.png


测试上一问题评论源代码:

image.png

总是尝试先 最小化代码----定位问题----优先看文档/寻找论坛旧文----解决问题...

非常感谢林间花老师~

考古...

\framebox是水平模式的盒子,其对齐的基线为bottom

可以使用adjustbox...这里有另一个类似的链接

\documentclass{article}
\usepackage{tabularray}
\usepackage{graphicx}
\usepackage{adjustbox}
\begin{document}
\begin{tblr}{
    colspec={X[12em,c]X[10em,c]},
    rowspec={|Q[m]|Q[m]|},
    stretch=0} 
    AAA & BBB\\
    \adjustimage{padding=\fboxsep,frame,width=\linewidth,valign=c}{example-image-duck}
     & $\{x \mid 0<x<4\}$\\
\end{tblr}
\end{document}

image.png

感谢@u64726 提供的思路,微调了一下...

\documentclass[b5paper,twoside,openany,UTF8]{ctexbook}
\usepackage{zhlipsum}
\usepackage{zhnumber}
\ctexset{
    chapter/name = {,},
    chapter/number = {\makebox[5\ccwd][s]{第\chinese{chapter}回}},
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[CO]{\zihao{5}\rightmark}
\fancyhead[CE]{\zihao{5}\leftmark}
\fancyfoot[RO]{--~\thepage~--}
\fancyfoot[LE]{--~\thepage~--}
\renewcommand{\headrulewidth}{0.5pt} 
\renewcommand{\chaptermark}[1]{%
    \markboth{\makebox[5\ccwd][s]{第\zhnumber{\thechapter}回}}{#1}
}
% 章节首页样式(无页眉和页眉横线,仅保留页码)
% 这是由于在book.cls中,章节首页预定义了样式 \thispagestyle{plain}
% 因此此处重定义 plain 样式相当于重定义了 章节首页
\fancypagestyle{plain}{%
    \fancyhf{}
    \fancyfoot[RO]{--~\thepage~--}
    \fancyfoot[LE]{--~\thepage~--}
    \renewcommand{\headrulewidth}{0pt}
}

\begin{document}
    \tableofcontents
    \chapter{这是一个标题名1}\zhlipsum[1-6]
    \addtocounter{chapter}{9}
    \chapter{这是一个标题名2}\zhlipsum[1-6]
    \addtocounter{chapter}{9}
    \chapter{这是一个标题名3}\zhlipsum[1-6]
\end{document}

image.png

(有没有什么方便的同时展现10+个pdf页面的截图方式啊...上图至少微调了2分钟大小...)

related link

\documentclass[12pt]{ctexart}
\usepackage{amsmath}
\usepackage{empheq}
\usepackage{bm}
\begin{document}

\begin{equation}
    a^2+b^2=c^2
\end{equation}

\begin{empheq}[left={a=\empheqlbrace}]{align}
    \dot{\bm{\lambda}} (t) &= -\frac{\partial H}{\partial \bm{x}}, \label{AA} \\
    \frac{\partial H}{\partial \bm{u}} &= 0, \label{BB} \\
    \dot{\bm{x}} &= \bm{f} (t,\bm{x}, \bm{u}), \notag
\end{empheq}

\begin{equation}
    a^2+b^2=c^2
\end{equation}

\end{document}

image.png

@u64726 Try This and consult for the .log file, by Eureka

\documentclass{article}
\listfiles
\begin{document}
test
\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

REF: https://tex.stackexchange.com/a/45206/294585

TeXLive2024+XeLaTeX一切正常,建议进一步检查宏包版本

可以在导言区使用\listfiles之后在.log文件中找到各个版本。

请提供你进行尝试的代码并说明具体是哪点的实现遇到了困难

可以参考这个链接

有的,考虑line cap=roundline join=round命令(可以texdoc tikz搜索)。

终于找到有人和我一样放大5000%倍pdf欣赏自己的TiKZpicture的了(握手)

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5,line cap=round,line join=round]
  \draw[domain=0:8, smooth, variable=\x]  plot ({\x}, {1/16*pow(\x, 2)});   
  \draw[domain=0:8, smooth, variable=\x]  plot ({\x}, {-1/16*pow(\x, 2)});
  \draw (8,0) ellipse (.4cm and 4cm);
\end{tikzpicture}%但我感觉还是差点意思

%如果不是完全追求 精确的函数关系的话
%可以试试控制点(?)
\begin{tikzpicture}[scale=.5,line cap=round,line join=round]
    \draw (0,0) .. controls (4,-.3) and (6,-2.3) .. (7.958,-3.98);
    \draw (0,0) .. controls (4,.3) and (6,2.3) .. (7.958,3.98);
    \draw (8,0) ellipse (.4 and 4);
\end{tikzpicture}

%不过代码似乎也不够优雅...

\end{document}

如果是精确的两条直线分别连接了同一个点的话,前面的round命令可以自动让这一切保持圆滑,但题主的问题中幂函数椭圆方程在数学上似乎本身就是相交的,这也许是导致出现需要微调的原因(?)

图床/或者说文件床最近挂了...你的mwe我打不开....

尝试了一下:

\documentclass{ctexart}
\usepackage{xcolor}
\usepackage[b5paper,landscape,showframe]{geometry}
\usepackage{needspace}
\usepackage{zhlipsum}
\usepackage{circledtext}
\ExplSyntaxOn    
\clist_new:N \g_my_parnote_clist
\clist_new:N \g_my_parnotetxt_clist
\makeatletter
\newcounter{parnotecnt}
\NewDocumentCommand{\parnote}{O{red} m m}{%
    \refstepcounter{parnotecnt}
    \unskip\textcolor{#1}{#2}\hbox{\@textsuperscript{\normalfont\circledtext[charf=\small]{\arabic{parnotecnt}}}}\unskip
    \clist_gput_right:Nn \g_my_parnote_clist {#2}
    \clist_gput_right:Nn \g_my_parnotetxt_clist {#3}
}
\makeatother     
\NewDocumentEnvironment{myenv}{+b}{%
    \setcounter{parnotecnt}{0}%
    \clist_clear:N \g_my_parnote_clist
    \clist_clear:N \g_my_parnotetxt_clist
    \needspace{\baselineskip}{\bfseries~【原文】}\par
    {#1} \par%\vspace{5pt}
    % \clist_use:Nn \g_my_parnote_clist {,}
    \clist_if_empty:NF {\g_my_parnote_clist}{%
         \needspace{.8\baselineskip}{\bfseries~【注释】}\par
         \int_step_inline:nn {\clist_count:N \g_my_parnote_clist}{%
            \noindent{##1}.~\clist_item:Nn \g_my_parnote_clist {##1}:~\clist_item:Nn \g_my_parnotetxt_clist {##1}~\par
         }
    }\vspace{2cm}%
}{}
\ExplSyntaxOff
\begin{document}
\begin{myenv}%
    \zhlipsum[2]
    测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本
\end{myenv}
\begin{myenv}%
    \zhlipsum[2]
    测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本测试文本\parnote{红色注释}{注释内容}测试文本\parnote[cyan]{蓝色注释}{注释内容}测试文本
    \zhlipsum
\end{myenv}

\begin{myenv}
    如果文段中没有\texttt{parnote},则不会输出【注释】\par
    \zhlipsum[2]
\end{myenv}

\end{document}

image.png

不太确定还有没有什么bug...

只是好奇,如果既不显示序号,也不显示脚注,那么你输入\footnote{这是一个脚注,但不会显示序号和文字。}是想告诉LaTeX什么信息呢? 序号+1?

也许提供一些必要的使用场景会更好一点。


也许是这个意思?设置\hidefootnotefalse正常显示:

\documentclass{ctexbook}
\usepackage[b6paper,landscape]{geometry}
\newif\ifhidefootnote
\hidefootnotefalse

\ifhidefootnote
\renewcommand*{\footnote}[1]{}
\fi

\begin{document}

    这是一段示例文字,\footnote{这是一个脚注,但不会显示序号和文字}脚注序号和脚注内容均不显示\footnote{这是一个脚注,但不会显示序号和文字}。

\end{document}

设置\hidefootnotetrue则隐藏脚注:

\documentclass{ctexbook}
\usepackage[b6paper,landscape]{geometry}
\newif\ifhidefootnote
\hidefootnotetrue

\ifhidefootnote
\renewcommand*{\footnote}[1]{}
\fi

\begin{document}

    这是一段示例文字,\footnote{这是一个脚注,但不会显示序号和文字}脚注序号和脚注内容均不显示\footnote{这是一个脚注,但不会显示序号和文字}。

\end{document}

发布
问题