XeLaTeX 下,xeCJK
可以使用 \xeCJKDeclareCharClass
全局的更改某个字符的字符类。你可以改了之后再改回来。
LuaLaTeX 下,luatexja
不支持修改 U+00 — U+7F 的 charrange。
XeLaTeX 下,xeCJK
可以使用 \xeCJKDeclareCharClass
全局的更改某个字符的字符类。你可以改了之后再改回来。
LuaLaTeX 下,luatexja
不支持修改 U+00 — U+7F 的 charrange。
问题出在 \newtheorem
并不会展开第 2 个参数,所以保留的是 \l_theorem_chinese_tl
的最后一个定义。
这里提供使用 \keyval_parse:nnn
的方法,比用 prop 更为简洁、快速。
\ExplSyntaxOn
% 使用方法 \addtheorem{<style>}{<environment name>=<Chinese name>, <environment name>, ...}
\NewDocumentCommand \addtheorem { m m }
{
\tl_set:Nn \l_theorem_style_tl {#1}
\keyval_parse:nnn { \__theorem_new_theorem:nn { } } { \__theorem_new_theorem:nn } {#2}
}
\cs_new:Npn \__theorem_new_theorem:nn #1#2
{
\theoremstyle { \l_theorem_style_tl }
\tl_if_empty:nTF {#1}
{
\exp_last_unbraced:Ne \newtheorem { {#2} { \text_titlecase_first:n {#2} } }
\exp_last_unbraced:Ne \newtheorem { * {#2*} { \text_titlecase_first:n {#2} } }
}
{
\newtheorem {#1} {#2}
\newtheorem * {#1*} {#2}
}
}
\ExplSyntaxOff
还额外支持没有给出 <chinese name>
的情况,此时把 <environment name>
第一个字母大写作为 <chinese name>
。如果不想要这个特性,把 \tl_if_empty:nTF
的 true 分支删掉即可。
比如:
\addtheorem{definition}{
definition = 定义,
assume = 假设,
lemma = 引理,
question = 问题,
corollary
}
\addtheorem{remark}{
remark = 注
}
如果不知道某一个命令会不会展开它的参数,最好的解决办法是先展开参数(用 \exp_args:N..
或 \exp_last_unbraced:N..
),再传递给这个命令。
第一,你的这个代码逻辑有问题。
第二,tblr
不会自动展开它的内容,必须使用 expand
选项设置要展开的命令,否则这个命令的内容会进入到某一个单元格中。
代码并不复杂:
\ExplSyntaxOn
\tl_clear:N \l_my_tmp_tl
\int_step_inline:nnn { 0 } { 18 }
{
\tl_put_right:Nn \l_my_tmp_tl
{ $ \sin #1^\circ = \fp_eval:n { sin( #1 * \c_one_degree_fp ) } $ }
\int_compare:nNnTF { \int_mod:nn { #1+1 } { 3 } } = { 0 }
{ \tl_put_right:Nn \l_my_tmp_tl { \\ } }
{ \tl_put_right:Nn \l_my_tmp_tl { & } }
}
\centering
\begin{tblr}[expand=\l_my_tmp_tl]{|c|c|c|}
\l_my_tmp_tl
\end{tblr}
\par
\ExplSyntaxOff
另一种排布:
\tl_clear:N \l_my_tmp_tl
\seq_clear:N \l_my_tmpa_seq
\seq_clear:N \l_my_tmpb_seq
\seq_clear:N \l_my_tmpc_seq
\int_step_inline:nnn { 7 } { 12 }
{
\seq_put_right:Nn \l_my_tmpb_seq
{ $ \sin #1^\circ = \fp_eval:n { sin( #1 * \c_one_degree_fp ) } $ }
}
\int_step_inline:nnn { 13 } { 18 }
{
\seq_put_right:Nn \l_my_tmpc_seq
{ $ \sin #1^\circ = \fp_eval:n { sin( #1 * \c_one_degree_fp ) } $ }
}
\int_step_inline:nnn { 0 } { 6 }
{
\tl_set:Nn \l_my_tmpa_tl { $ \sin #1^\circ = \fp_eval:n { sin( #1 * \c_one_degree_fp ) } $ }
\seq_pop_left:NNF \l_my_tmpb_seq \l_my_tmpb_tl
{ \tl_set_eq:NN \l_my_tmpb_tl \c_empty_tl }
\seq_pop_left:NNF \l_my_tmpc_seq \l_my_tmpc_tl
{ \tl_set_eq:NN \l_my_tmpc_tl \c_empty_tl }
\tl_put_right:Nx \l_my_tmp_tl
{ \exp_not:o \l_my_tmpa_tl & \exp_not:o \l_my_tmpb_tl & \exp_not:o \l_my_tmpc_tl \exp_not:N \\ }
}
\begin{tblr}[expand=\l_my_tmp_tl]{|c|c|c|}
\l_my_tmp_tl
\end{tblr}
\par
另外,TeX 的计算结果并不一定十分准确,专业的计算交给专业的软件。
在 LaTeX2e 中有 \newcommand{\...}[num]{...}
,这种用法,\cs_generate_from_arg_count:NNnn
是对它的一个扩展。
这个函数是有用的,例如,\cs_set:Nn
可以这样定义:
先得到要定义的函数的 signature(比如:\cs_set:Npn
中的 Npn
),然后计算 signature 中的字符数,再由 \cs_generate_from_arg_count:NNnn
生成。
另一个例子是 \NewDocumentCommand
的定义。例如 \NewDocumentCommand \cs { mm } {...}
,可以看出 \cs
接受 2 个参数,直接使用 \cs_generate_from_arg_count:NNnn \cs \cs_new_protected_nopar:Npn { 2 } {...}
定义即可(当然,实际上更加复杂)。
外面的盒子自己改。用 tikz
、tcolorbox
都可以。改颜色、字体、\parttocbox
\chaptertocbox
\chaptertocdashed
即可,其它的基本不用改。
目前的效果是这样:
\documentclass{ctexbook}
%\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{paracol}
\usepackage{etoc}
\usepackage{calc}
\usepackage{varwidth}
%\usepackage{hyperref}
\begin{document}
\makeatletter
\newlength{\parttocsep}
%%%---只需改这中间的即可,如果要改间距再改后面的
\newcommand{\toccolorlist}{black,red!70,green!30!black,cyan,black!70}
%% 颜色自己加,使用逗号分割即可,在目录中 \tocthecolor 保存了当前值
\setlength{\parttocsep}{12pt plus 4pt minus 4pt}
% #1=number, #2=name, #3=page
\newcommand{\parttocbox}[3]{\zihao{-3}\fbox{#3}\hfill
\parbox[t]{.7\columnwidth}{#1\par \large #2}}
\newcommand{\chaptertocbox}[3]{%
\fbox{\parbox{2em}{#1}%
\begin{varwidth}{\linewidth-4em}#2\end{varwidth}}\hfill#3}
\newcommand{\chaptertocdashed}{\noindent\makebox[\columnwidth]{\dotfill}}
\newcommand{\tocinitials}{\columnratio{.33}
\twosided[m]%
\setlength{\columnseprule}{3pt}% 中间的线宽
\setlength{\parindent}{0pt}}
\newcommand{\parttoccode}{{\parttocbox{Part \etocnumber}{\etocname}{\two@digits{\etocthepage}}\par}}
\newcommand{\chaptertoccode}{{\chaptertocbox{\etocnumber}{\etocname}{\etocpage}\par}}
\newcommand{\sectiontoccode}{\@dottedtocline{1}{3em}{3.7em}{\etocnumber\enskip\etocname}{\etocpage}}
\newcommand{\subsectiontoccode}{\@dottedtocline{2}{6.7em}{2.6em}{\etocnumber\etocname}{\etocpage}}
\newcommand{\subsubsectiontoccode}{\@dottedtocline{3}{6.7em}{2.6em}{\etocnumber\etocname}{\etocpage}}
%%%---
\ExplSyntaxOn
\tl_set:Nn \tocthecolor {black}
\cs_new_protected:Npn \toccolor #1
{
\tl_set:Nx \tocthecolor
{
\clist_item:Nn \toccolorlist
{ \int_mod:nn {#1} { \clist_count:N \toccolorlist } + 1 }
}
\normalcolor
}
\ExplSyntaxOff
\newcommand{\tocnumberline}[1]{%
\protect\numberline{\CTEXifname{\number\value{#1}}{0}}}
%% 必须留着
\ctexset{part/tocline=\tocnumberline{part}{#2},
chapter/tocline=\tocnumberline{chapter}{#2},
section/name={第,节},section/number=\arabic{section},
subsection/number={\thesection.\arabic{subsection}},}
\renewcommand*{\thesection}{\arabic{chapter}.\arabic{section}}
\counterwithin{chapter}{part}
\begingroup
\etocsetstyle{part}
{}
{\@bsphack\tocinitials\@esphack
\def\normalcolor{\color{\tocthecolor}}%
\etociffirst{}{\addvspace{\parttocsep}}%
\begin{paracol}{2}}
{\switchcolumn[0]* \toccolor{\etocthenumber}\parttoccode}
{}
\etocsetstyle{chapter}
{\switchcolumn \nointerlineskip}
{\etociffirst{}{\par\chaptertocdashed\par}}
{\chaptertoccode\par \prevdepth-\@m\p@ \vspace{1ex+\lineskip}\par}
{\end{paracol}}
\etocsetstyle{section}
{\par}
{}
{\sectiontoccode}
{\par\prevdepth-\@m\p@ \vspace{1ex+\lineskip}\par}
\etocsetstyle{subsection}
{\par}
{}
{\subsectiontoccode}
{\par}
\etocsetstyle{subsubsection}
{\par}
{}
{\subsubsectiontoccode}
{\par}
\tableofcontents
\endgroup
\makeatother
\part{一个部分}
\chapter{介绍}
\section{引言}
\chapter{简明教程}
\part{编译方式、编码与字库}
\chapter{常见的编译方式有哪些}
\chapter{不同的编码}
\chapter{字库}
\part{章节标题设置方式大全}
\chapter{章节标题样式设计大全(不使用宏包直接设置方法)}
\section{编号相关}
\section{格式相关}
\section{间距相关}
\section{目录、附录}
\subsection{小小节但是名字很长的节}
\subsection{小心地}
\section{很长很长很长很长很长的标题怎么设置}
\chapter{章节标题样式设计大全(宏包)}
\chapter{一分为二的标题}
\chapter{一些样式}
\part{长标题是怎样排版的?长标题是怎样换行的?}
\chapter{长标题要断行该使用什么样的命令或环境呢?}
\chapter{短标题}
\chapter{不得使用titlesec宏包}
\chapter{直接用ctex设置}
\chapter{1234567}
\end{document}
使用 etoc
宏包,虚线见 https://ask.latexstudio.net/ask/question/7397.html 。
\documentclass{ctexrep}
\usepackage{enumitem}
\usepackage{etoc}
%\usepackage[colorlinks]{hyperref}
\setmainfont{TeX Gyre TermesX}
\usepackage{dashrule}
\begin{document}
\ExplSyntaxOn
% https://ask.latexstudio.net/ask/question/7397.html
\NewDocumentCommand \approxhdashrule { O{0pt} m m m }
{
\hbox_to_wd:nn {#2}
{
\int_set:Nn \l_tmpa_int
{
2 * \int_div_round:nn { \int_value:w \tex_dimexpr:D #2 }
{ 2 * \int_value:w \tex_dimexpr:D #4 } + 1
}
\dim_set:Nn \l_tmpa_dim { \dim_eval:n {#2} / \l_tmpa_int }
\hdashrule [#1] {#2} {#3} { \l_tmpa_dim }
\hbox_overlap_left:n { \rule [#1] { \l_tmpa_dim } {#3} }
}
}
\ExplSyntaxOff
\ctexset{section/tocline={\protect\numberline{第\chinese{section}节}#2}}
\makeatletter
\newlist{thetoclist}{itemize}{5}
% chapter
\setlist[thetoclist,1]{nosep,label=\etocnumber,
left=0cm..5\ccwd,labelsep=1\ccwd}
% section
\setlist[thetoclist,2]{nosep,label=\etocnumber,
left=5\ccwd..4\ccwd,labelsep=1\ccwd}
\newcommand{\thetoc@dashed}{\noindent
\approxhdashrule[.6ex]{\linewidth}{.6pt}{4pt}\par}
\let\thetocdashed\relax
\providecommand{\three@digits}[1]{\ifnum#1<10 0\fi
\ifnum#1<100 0\fi \number#1 }
\etocsetstyle{chapter}
{\begin{thetoclist}}
{\etociffirst{}{\thetoc@dashed}%
\rmfamily\bfseries\item}
{\etocname\hfill \slshape\three@digits\etocthepage}
{\end{thetoclist}}
\etocsetstyle{section}
{\begin{thetoclist}}
{\normalfont\item}
{\etocname\hfill \slshape\three@digits\etocthepage}
{\end{thetoclist}}
\localtableofcontents
\makeatother
\cleardoublepage
\pagenumbering{arabic}
\chapter{双相障碍及精准医学}
\section{双相障碍概念}
\section{精准医学概念}
\chapter{双相障碍的临床表现}
\section{临床表现及分型}
\section{抑郁发作}
\setcounter{chapter}{10}
\chapter{双相障碍的病因机制假说}
\section{遗传与环境交互作用假说}
\end{document}
\documentclass{article}
\usepackage{enumitem}
\makeatletter
\newcommand\twodigitsarabic[1]{\two@digits{\value{#1}}}
\AddEnumerateCounter{\twodigitsarabic}{\@arabic}{99}
\makeatother
\begin{document}
\begin{enumerate}[label={\twodigitsarabic*.}]
\item content
\item content
\item content
\end{enumerate}
\end{document}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{3}
&& \| S+T \|^{2}_{A}& = \omega ^{2}_{A}(S+T) && \\
&& & \leq \sup_{\|x\|_{A}=1}(|\langle (S+iT)x,x \rangle _{A} |^{2} && \\
&& & & \text{\llap{(by Lemma)}} & \\
&& & \leq \sup_{\|x\|_{A}=1}(|\langle (S+iT)x,x \rangle _{A} |^{2} && \\
\end{alignat*}
\end{document}
我没有下载 texstudio,
你可以换成 \lstinline|...|
试试,
不行再改成
\newcommand\myinline{\lstinline}
\myinline{...}
试试。
目前,TeX 的代码高亮不可能做到像其它编程语言的一样好。
ctex
在 pdftex 下使用 CJK
宏包,应该是和 newunicodechar
不兼容的。
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{newunicodechar}
\DeclareUnicodeCharacter{1F994}{\LaTeX}
\begin{document}
what?
????%% <-- U+1F994
\end{document}
这个可以在 pdftex 下编译,但改成 ctex 文档类就不行了。
第一个,由于 geometry
可能会改变正文宽度,页眉页脚宽度也会随之改变,\pagestyle
必须在 geometry
之后使用,或者在 geometry
之后加上 \fancyhfoffset{0pt}
,这样才能更新页眉页脚的宽度。
第二个,log 文件中已经写了:
Package fancyhdr Warning: \fancyhead's `E' option without twoside option is use
less on input line 9.
fancyhdr
的奇偶设置必须使用 twoside
文档类选项:\documentclass[twoside]{article}
。
实际上,PunctuationSpace
设置的是 \fontdimen7
的值。只有两个词中间的 \spacefactor
大于等于 2000 时,才会使用到这个值(即增加设置的这个间距)。
但是,一般情况下,;
和 ,
的 space factor 都是小于 2000 的,所以它们并不会像其它标点一样增加间距。
只要设置它们的 space factor 大于等于 2000 即可。比如:
\sfcode`\;2500 \sfcode`\,2250
如果整篇文章的标点都要增加额外的间距的话,最好是重定义 \nonfrechspacing
:
\DeclareRobustCommand\nonfrenchspacing{\sfcode`\.3000 \sfcode`\?3000
\sfcode`\!3000 \sfcode`\:2750 \sfcode`\;2500 \sfcode`\,2250 }
\documentclass{article}
\usepackage{fontspec}
\DeclareRobustCommand\nonfrenchspacing{\sfcode`\.3000 \sfcode`\?3000
\sfcode`\!3000 \sfcode`\:2750 \sfcode`\;2500 \sfcode`\,2250 }
\nonfrenchspacing
\begin{document}
I can eat glass, it doesn't hurt me. I can eat glass, it doesn't hurt me.
\fontspec[PunctuationSpace=2]{Latin Modern Roman}
I can eat glass, it doesn't hurt me. I can eat glass, it doesn't hurt me.
\fontspec[PunctuationSpace=10]{Latin Modern Roman}
I can eat glass, it doesn't hurt me. I can eat glass, it doesn't hurt me.
\end{document}
要注意的是,如果标点符号前是大写字母,且并非缩写(比如 B.C. 这种),则需正确设置标点符号前的 space factor:
It is NASA. It is NASA\@.
It is nasa. It is nasa.
\documentclass{article}
\usepackage{amsmath}
\usepackage{stackengine}
\usepackage{scalerel}
\newcommand\mysqrt[2][0pt]{\stretchrel{\sqrt{}}{\addstackgap%
[#1]{$\displaystyle\overline{#2}$}}}
\begin{document}
\[ \mysqrt[1.1pt]{ \begin{vmatrix} a&b&c\\ d&e&f\\ g&h&i \end{vmatrix} } \]
\end{document}
见:https://tex.stackexchange.com/a/128119/232375
这种情况也可以考虑用指数表示。
小写的 o
才可以用 \IfNoValueTF
判断:
\NewDocumentEnvironment{example}{oo}
{%
\IfNoValueTF{#1}{...}{...}%
\IfNoValueTF{#2}{...}{...}%
}
{}
大写的 O
D
等参数,如果不给出,则使用默认值。
小写的 o
d
等参数,如果不给出,则返回特殊的 -NoValue-
,可以用 \IfNoValueTF
判断。
这是因为你使用了 Consolas 字体,而这个字体中没有这个 "␣"(U+2423,\textvisiblespace
) 字符。可以在 log 文件中看到这一点。
如果必须使用 Consolas 字体,只要设置 showstringspaces=false
就可以了。
可以直接用 \lstset{showstringspaces=false}
,也可以
\begin{lstlisting}[language=R,showstringspaces=false]
> grep("Pole",c("Equator","North Pole","South Pole"))
[1] 2 3
> grep("pole",c("Equator","North Pole","South Pole"))
integer(0)
# 看看区别
> grepl("Pole",c("Equator","North Pole","South Pole"))
[1] FALSE TRUE TRUE
> grepl("pole",c("Equator","North Pole","South Pole"))
[1] FALSE FALSE FALSE
\end{lstlisting}
问 如何临时设置标点类型?