Sagittarius Rover
Sagittarius Rover
这家伙很懒,什么也没写!

注册于 4年前

回答
540
文章
0
关注者
21

几个建议:

  • 首先不要盲目地听信AI直接修改配置文件
  • 要理解任何配置(sublime/vscode/texstudio)的本质都是编辑器在按照某套既定的规则帮助你在命令行输入命令
  • 基于上一点,应该先构造一个最简单的测试样例
\documentclass{article}
\usepackage{glossaries}
\makeglossaries

\newglossaryentry{latex}{
    name={LaTeX},
    description={A document preparation system}
}

\begin{document}

This document is written using \gls{latex}.

\printglossaries

\end{document}
  • 确保某一组命令在命令行测试编译通过
  • 最后再研究sublime的配置要如何设置这套「既定的规则」

要正确编译上面的文档,有两种方案:

1.多次编译:

pdflatex main
makeglossaries main
pdflatex main

2.或者使用latexmk,但也不能太直接一步到位,参考这个链接

在codex老师的帮助下,我发现我在windows下需要微调一下.latexmkrc

add_cus_dep('glo', 'gls', 0, 'run_makeglossaries');
add_cus_dep('acn', 'acr', 0, 'run_makeglossaries');

sub run_makeglossaries {
    my ($base_name, $path) = fileparse( $_[0] ); #handle -outdir param by splitting path and file, ...
    pushd $path; # ... cd-ing into folder first, then running makeglossaries ...

    if ( $silent ) {
        # system "makeglossaries -q '$base_name'"; #unix
        system "makeglossaries", "-q", "$base_name"; #windows
    }
    else {
        # system "makeglossaries '$base_name'"; #unix
        system "makeglossaries", "$base_name"; #windows
    };

    popd; # ... and cd-ing back again
}

再用

latexmk -pdf main

image.png

现在要做的,就是如何把上述配置移植到 sublime 风格的配置文件上,让他实际上做和上面命令行完全相同的事。

有类似原理支持相关功能的 hwemoji 宏包,担任让不支持与ctex共同使用。

\documentclass{article}
% \usepackage{ctex}
\usepackage{hwemoji}
\begin{document}

\texttt{pdflatex-friendly} 

%中文 + emoji ?

✏ 🆔 🍄 😀 😁

\end{document}

image.png

image.png

哎哎... CJK的内部实现想必修改了某些映射...不过为什么pdftex-only呢....2026年了,pdflatex+CJK也许已经不是主流,除非是在维护某些旧文档...

应但是bug...

理论上lang=cnlang=it都应该覆盖\bibname,不应该出现这种行为的不一致性。

以下部分由codex-5.5辅助生成:

第一步:定位 elegantbook.cls 中两段代码的差异

elegantbook.cls 中,语言分支的代码结构如下:

cn 分支(第 192-219 行 + 第 409-453 行):

% 第 194 行:加载 ctex 处理中文排版
\RequirePackage[UTF8, scheme=plain, fontset=none]{ctex}

% 第 418 行:手动重定义 \bibname
\renewcommand{\bibname}{参考文献}

cn 分支没有加载 babel,也没有做任何与 biblatex 语言字符串相关的设置。

it 分支(第 492-526 行):

% 第 494 行:加载 babel 意大利语
\RequirePackage[italian]{babel}

it 分支甚至没有手动写 \renewcommand{\bibname}{...},但 \printbibliography 的标题却是正确的意大利语。

第二步:确认 biblatex 的加载位置

% 第 403-407 行:biblatex 在语言分支之前加载
\RequirePackage[
  backend=\ELEGANT@bibend,
  citestyle=\ELEGANT@citestyle,
  bibstyle=\ELEGANT@bibstyle]{biblatex}

加载顺序为:

  1. ctexbabel(语言分支,第 192 行起)
  2. biblatex(第 407 行)
  3. 各语言的 \renewcommand 覆盖(第 409 行起)

第三步:理解 biblatex 的标题机制

biblatex 有两套并行的标题系统

系统机制命令
LaTeX 标题宏\bibname / \refname\renewcommand 修改
biblatex 本地化字符串bibliography / references.lbx 文件或 \DeclareBibliographyStrings 定义

关键点:\printbibliography 的默认标题不是直接读取 \bibname,而是读取 biblatex 自己的本地化字符串 bibliography。biblatex 在初始化和 \begin{document} 时刻会用自己的字符串系统同步覆盖 \bibname

第四步:追踪两种语言的完整链路

lang=it 的完整链路:

elegantbook.cls 第 494 行:
  \RequirePackage[italian]{babel}
       ↓
  babel 将文档主语言注册为 italian
       ↓
  biblatex 检测到 babel 语言为 italian
       ↓
  自动加载 italian.lbx
  (路径:texmf-dist/tex/latex/biblatex/lbx/italian.lbx)
       ↓
  italian.lbx 第 90 行定义:
    bibliography = {{Bibliografia}{Bibliografia}}
       ↓
  \begin{document} 时,biblatex 用 italian.lbx 的字符串初始化
       ↓
  \printbibliography 标题 → Bibliografia ✓

lang=cn 的完整链路:

elegantbook.cls 第 194 行:
  \RequirePackage[...]{ctex}
       ↓
  ctex 只处理中文排版(字体、断行等),不注册 babel 语言
       ↓
  biblatex 检测不到中文语言环境
       ↓
  且 biblatex 标准发行版中没有 chinese.lbx
       ↓
  biblatex 回退到默认语言 → english
       ↓
  english.lbx 定义:
    bibliography = {{Bibliography}{Bibliography}}
       ↓
  elegantbook.cls 第 418 行:
    \renewcommand{\bibname}{参考文献}
  ← 此时 \bibname 暂时被改为"参考文献"
       ↓
  \begin{document} 时,biblatex 用 english.lbx 的字符串
  重新初始化,\bibname 被覆盖回 "Bibliography"
       ↓
  \printbibliography 标题 → Bibliography ✗

第五步:验证——为什么两种绕过方式有效

用户提到的两种绕过方式:

% 方式一:延迟到 \begin{document} 之后覆盖
\AtBeginDocument{%
    \renewcommand{\bibname}{参考文献}
}

有效原因:\AtBeginDocument 在 biblatex 的 \begin{document} 初始化之后执行,所以覆盖不会被 biblatex 再冲掉。

% 方式二:直接指定标题
\printbibliography[title={参考文献}]

有效原因:title= 参数直接覆盖了 biblatex 的默认标题逻辑,绕过了整个字符串系统。


根因结论

lang=itlang=cn
语言包\RequirePackage[italian]{babel}\RequirePackage[...]{ctex}
是否注册 babel 语言
biblatex 识别的语言italianenglish(回退默认)
biblatex 加载的 .lbxitalian.lbxenglish.lbx
bibliography 字符串BibliografiaBibliography
\renewcommand{\bibname} 是否生效不需要(.lbx 已处理)写了但被 biblatex 覆盖

一句话总结lang=it 之所以正常,是因为 \RequirePackage[italian]{babel} 触发了 biblatex 自身的本地化机制(加载 italian.lbx),biblatex 从自己的字符串系统中获得了正确的意大利语标题。而 lang=cn 只是通过 \renewcommand{\bibname}{参考文献} 修改了 LaTeX 层面的标题宏,并没有对接 biblatex 的本地化字符串系统;biblatex 在 \begin{document} 时仍按默认的 english.lbx 重新初始化 \bibname,导致中文设置被覆盖。

这本质上是 elegantbook.cls 的 lang=cn 分支只做了一半的工作:改了 LaTeX caption macro,但遗漏了 biblatex 的 DeclareBibliographyStrings 接口。


推荐修复方案

elegantbook.clslang=cn 分支中,用 \DefineBibliographyStrings 接入 biblatex 的本地化字符串系统。由于 cn 分支没有注册 babel 语言,biblatex 实际加载的是 english.lbx,所以需要覆盖 english 语言的字符串。

修改位置

elegantbook.cls 第 418-419 行之后(\bibname\ebibname 定义之后),添加:

\ifdefstring{\ELEGANT@lang}{cn}{
  \renewcommand{\baselinestretch}{1.3}
  \renewcommand{\contentsname}{目录}
  \renewcommand{\figurename}{图}
  \renewcommand{\tablename}{表}
  \renewcommand{\partname}{\color{structurecolor}}
  \renewcommand{\thepart}{第\zhnumber{\arabic{part}}部分}
  \renewcommand{\listfigurename}{插图目录}
  \renewcommand{\listtablename}{表格目录}
  \renewcommand{\bibname}{参考文献}
  \newcommand{\ebibname}{参考文献}
  % >>> 新增:接入 biblatex 本地化字符串系统 >>>
  \DefineBibliographyStrings{english}{
    bibliography = {参考文献},
    references   = {参考文献},
  }
  % <<< 新增结束 <<<
  \renewcommand{\appendixname}{附录}
  % ... 后续不变 ...
}{\relax}

修改后的测试:

\documentclass[
    lang=cn,fontset=fandol,
]{elegantbook}
\geometry{paperheight=8cm}
\addbibresource{xampl.bib}
\begin{document}

\chapter{第一章}
Hello\cite{article-minimal} World! 中文!

\printbibliography

\end{document}

image.png

以下的分析来自 codex-5.5-xhigh:

原因是 book.cls\tableofcontents\@mkboth 放进了 \chapter*{...} 标题参数里;你的 \titleformat 又把该标题交给 \myroundedbox',其中 xstring' 的 \StrLeft/\StrGobbleLeft 会拆解整个 token list,触发 \@mkboth 递归,最终报 TeX capacity exceeded [input stack size=10000]
我已采用最佳修正:重定义 \tableofcontents,把 \@mkboth 移到 \chapter*{\contentsname} 之后执行。这样目录标题装饰宏只处理可见文字“目录”,不再处理页眉标记命令。
\documentclass[fontset=fandol]{ctexbook}
\RequirePackage{titlesec}
\RequirePackage{fancyhdr}
\RequirePackage{xstring}
\RequirePackage{tikz}
\newcommand{\myroundedbox}[1]{%
  \begin{tikzpicture}[baseline=(mbox.base), overlay, remember picture]
    \StrLeft{#1}{1}[\firstchar]
    \StrGobbleLeft{#1}{1}[\restchars]
    \node[anchor=west,draw=cyan,line width=2pt,fill=white,inner xsep=3pt,inner ysep=3pt,font=\bfseries] (mbox) {\firstchar\hskip 0.3em\restchars};
  \end{tikzpicture}%
}
\titleformat{\chapter}[display]
  {%
    \sffamily%
    \thispagestyle{empty}
  }
  {}
  {-1.1em}
  {\myroundedbox}
\titlespacing{\chapter}{0pt}{-1.5\baselineskip}{0\baselineskip}
% book.cls puts \@mkboth inside the TOC chapter title; keep it outside
% because \myroundedbox uses xstring to split only visible title text.
\makeatletter
\renewcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname}%
    \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }
\makeatother

\begin{document}

\tableofcontents %

\chapter{课节导引}
\section{引导点公式速记速记}

\end{document}

如上的 patch 可以似乎可以解决问题...

image.png

Claim:这不是一个回答,只是必要的简化。

该问题的一个简化版本等价于:

\documentclass[fontset=fandol]{ctexbook}
\RequirePackage{titlesec}
\RequirePackage{fancyhdr}
\RequirePackage{xstring}
\RequirePackage{tikz}
\newcommand{\myroundedbox}[1]{%
  \begin{tikzpicture}[baseline=(mbox.base), overlay, remember picture]
    \StrLeft{#1}{1}[\firstchar]
    \StrGobbleLeft{#1}{1}[\restchars]
    \node[anchor=west,draw=cyan,line width=2pt,fill=white,inner xsep=3pt,inner ysep=3pt,font=\bfseries] (mbox) {\firstchar\hskip 0.3em\restchars};
  \end{tikzpicture}%
}
\titleformat{\chapter}[display]
  {%
    \sffamily%
    \thispagestyle{empty}
  }
  {}
  {-1.1em}
  {\myroundedbox}
\titlespacing{\chapter}{0pt}{-1.5\baselineskip}{0\baselineskip}

\begin{document}

% \tableofcontents %

\chapter{课节导引}
\section{引导点公式速记速记}

\end{document}

如果加上\tableofcontents,将导致如下报错:

! TeX capacity exceeded, sorry [input stack size=10000].
\@mkboth ...rotect \ttl@gmk {\protect \@mkboth {#1
                                                  }{#2}}
l.25 \tableofcontents

另外,对于这种站内的链接,不建议不贴文件。否则这隐含着让其他人都要付费下载一次。

能否请 @u122987 关注一下。

Code1. 源代码

\documentclass[zihao=-4]{ctexbook}
\RequirePackage[
    papersize={210mm,297mm},
    margin=25mm,showframe,
    ]{geometry} 
\RequirePackage{enumitem} 

\usepackage{newtxtext}

\begin{document}

\begin{enumerate}[label={[}\arabic*{]}, labelindent=\parindent, leftmargin=*]
    \item Tao Y, \textbf{Liu H}, Wang X, et al. Probabilistically Informed Motion Primitives for Impedance Control with Guided Motion Planning in Contact-Rich Manipulation Tasks[J]. xxxx. (学生一作在投,SCI,Q1, IF=4.7,对应第四章)
\end{enumerate}

\end{document}

A. xelatex+newtxtext

B. lualatex+newtxtext

Code2.添加\usepackage[british]{babel}


\documentclass[zihao=-4]{ctexbook}
\RequirePackage[
    papersize={210mm,297mm},
    margin=25mm,showframe,
    ]{geometry} 
\RequirePackage{enumitem} 
\usepackage[british]{babel}
\usepackage{newtxtext}

\begin{document}

\begin{enumerate}[label={[}\arabic*{]}, labelindent=\parindent, leftmargin=*]
    \item Tao Y, \textbf{Liu H}, Wang X, et al. Probabilistically Informed Motion Primitives for Impedance Control with Guided Motion Planning in Contact-Rich Manipulation Tasks[J]. xxxx. (学生一作在投,SCI,Q1, IF=4.7,对应第四章)
\end{enumerate}

\end{document}

A. xelatex+newtxtext+\usepackage[british]{babel}

B. lualatex+newtxtext+\usepackage[british]{babel}

Code3.使用\hyphenation{im-ped-ance}

\documentclass[zihao=-4]{ctexbook}
\RequirePackage[
    papersize={210mm,297mm},
    margin=25mm,showframe,
    ]{geometry} 
\RequirePackage{enumitem} 
\hyphenation{im-ped-ance}
\usepackage{newtxtext}

\begin{document}

\begin{enumerate}[label={[}\arabic*{]}, labelindent=\parindent, leftmargin=*]
    \item Tao Y, \textbf{Liu H}, Wang X, et al. Probabilistically Informed Motion Primitives for Impedance Control with Guided Motion Planning in Contact-Rich Manipulation Tasks[J]. xxxx. (学生一作在投,SCI,Q1, IF=4.7,对应第四章)
\end{enumerate}

\end{document}

A.xelatex+\hyphenation{im-ped-ance}:

B.lualatex+\hyphenation{im-ped-ance}:

Code4.添加microtype(但只在lualatex下生效,感谢@u30 )

% lualatex
\documentclass[zihao=-4]{ctexbook}
\RequirePackage[
    papersize={210mm,297mm},
    margin=25mm,showframe,
    ]{geometry} 
\RequirePackage{enumitem} 
\usepackage{newtxtext}
\usepackage{microtype} 

\begin{document}

\begin{enumerate}[label={[}\arabic*{]}, labelindent=\parindent, leftmargin=*]
    \item Tao Y, \textbf{Liu H}, Wang X, et al. Probabilistically Informed Motion Primitives for Impedance Control with Guided Motion Planning in Contact-Rich Manipulation Tasks[J]. xxxx. (学生一作在投,SCI,Q1, IF=4.7,对应第四章)
\end{enumerate}

\end{document}

我试了一下,虽然没有任何提示,但是在这个网页 只要耐心等一分钟就可以触发自动下载

但为何在macOS下,却无法在终端中使用makeglossaries命令编译词汇表,提示找不到命令

终端能找到系统程序的必要条件是 makeglossaries.exe 需要在系统的 $PATH 路径下,可以尝试一下环境变量路径下是否真的有 makeglossaries.exe 这个程序。

\documentclass[fontset=fandol]{ctexbeamer}
% Refs: https://tex.stackexchange.com/a/380895
% \usepackage{multicol}
\xdefinecolor{mycolor}{RGB}{0,102,204}
\begin{document}
{%
\setbeamertemplate{headline}{}
\setbeamertemplate{footline}{}
\begin{frame}[plain]%
    % \vspace*{\fill}
    \centering
    {\Huge \bfseries \textcolor{mycolor}{目录}}%
    \vspace{1.2em}%
    \textcolor{mycolor}{\hrule}
    \vspace{1.5em}%
    % \begin{minipage}{0.85\textwidth}%
    %     \begin{multicols}{2}
    %         \tableofcontents[hideallsubsections]
    %     \end{multicols}
    % \end{minipage}
    \begin{columns}
        \begin{column}{.3\textwidth}%
            \tableofcontents[sections=1-3,hideallsubsections]
        \end{column}%
        \begin{column}{.3\textwidth}%
            \tableofcontents[sections=4-6,hideallsubsections]
        \end{column}%
    \end{columns}%
\end{frame}%
}
\section{第一章 研究背景}
\section{第二章 研究意义}
\section{第三章 研究内容}
\section{第四章 研究方法}
\section{第五章 技术路线}
\section{第六章 总结展望}

\begin{frame}
    正文
\end{frame}
\end{document}

BTW, xdefinecolor好像很少见...

请用「CTeX套装」试试而不是「TeXLive/Miktex」。同时如果还不行,请详细说明你具体是怎么做的,报错信息是什么?

Refs: https://ask.latexstudio.net/ask/question/17778.html

很简单的办法参考自: https://ask.latexstudio.net/ask/question/8198.html

对于这种分段函数,直接使用tikz用直线绘制即可,你甚至可以很方便的控制颜色,线条样式、粗细等特征:

\documentclass[tikz,border=5pt]{standalone}
\usepackage[fontset=fandol]{ctex}
\usepackage[osf]{libertine} % 我喜欢的一款字体
\begin{document}

\begin{tikzpicture}[
    line cap=round,
    every node/.style={black}
    ]
\draw[-latex] (0,0) -- (6,0) node[below]{t(h)};
\draw[-latex] (0,0) -- (0,6) node[right]{s(km)};

\node[below left] {0};

\foreach \i in {1,...,5}{
    \draw(0,\i) node[left] {\inteval{10*\i}} -- ++(.2,0);
    \draw(\i,0) node[below] {\inteval{\i}} -- ++(0,.2);
}

\draw[magenta,thick] (0,0) 
    -- (1,3) node[left] {A} 
    -- (1.5,3) node[right] {B} 
    -- (2,5) node[above left=-1pt] {C} 
    -- (2.75,5) node[above right=-1pt] {D} 
    -- (5,0) node[above right=-1pt] {E}
    ;
\draw[cyan,dashed,semithick] (0,5) 
    -- (.5,5) node[above] {G}
    -- (3,0) node[above right] {H}
    ;

\draw[cyan,dashed,semithick] (5.75,5.25) -- ++(-1,0) node[left,anchor=east] {小聪};
\draw[magenta,thick] (5.75,4.5) -- ++(-1,0) node[left,anchor=east] {小慧};

\end{tikzpicture}

\end{document}

image.png

当然,这里有个小难点是如何恰好让「B」点相交,我是做了一些斜率的预计算。放轻松,每一行命令的功能都是比较简单的,你可以注释某行代码再编编译看看结果,相信学会这种绘制并不算太难~

Happy TikZing!

使用chemfig宏包酚醛树脂的缩聚反应方程式如何写,达到图片上的效果,特别是方括号及高分子连线那部分

具体是哪里不会呢?看上去是只有方括号和连线没处理好,请展示你现在已有的代码,避免问「do-this-for-me类」的问题。


不是非常优雅的一些暴力微调...

\documentclass{article}%
\usepackage{newpxmath}%
\usepackage{chemfig}
\usepackage{mhchem}
\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}}
\begin{document}
\[
    \setchemfig{atom sep=2em}
    \hreac%[hreac debug]
        \^{2pt}$n$\;\chemfig[baseline=10pt]{*6([,0.75]=-=(-[0]CH_2OH)-(-[2]OH)=-)}
        >[{\ce{H+}}][{$\triangle$}]
        \^{2pt}\chemfig{H-[@{op,.5}]([:-30]*6([,0.75]-=-=(-[0]CH_2-[0]@{cl,0}-[0]OH)-(-[2]OH)=))}
        \polymerdelim[delimiters ={[]}, height = 5pt, depth=22.5pt]{op}{cl}
        + $(n - 1)$\ce{H2O}
        \endhreac
\]
\end{document}

image.png

Just refer the manual in texdoc nicematrix and a little bit in texdoc tikz:

\documentclass{article}
\usepackage{fourier}
\usepackage{nicematrix,tikz}
\usepackage{lipsum}
\usetikzlibrary{arrows.meta}
\begin{document}

\lipsum[2][1-3]

\[  
\renewcommand{\arraystretch}{1.5}%
\begin{pNiceArray}{ccc;ccc}[margin] % new feature `;' in nicematrix v7.7
\CodeBefore%
\tikz{%
    \draw[-Stealth] ([xshift=-1cm,yshift=.05cm]1.5|-2) node[above] {$(-2)$} |- ([xshift=-.5cm]1.5|-2.5);
    \draw[-Stealth] ([xshift=-1.75cm,yshift=.05cm]1.5|-2) node[above] {$(-1)$} |- ([xshift=-.5cm]1.5|-3.5);
}
\Body
1 & 2 & 3 & 1 & 0 & 0 \\
2 & 1 & 2 & 0 & 1 & 0 \\
3 & 2 & 1 & 0 & 0 & 1 \\
\end{pNiceArray}
\]

\lipsum[2][1-3]

\end{document}

image.png

发布
问题