我是一个相当不错的 LaTeX 用户,因为我一直在写 LaTeX 文档,而且我可以做几乎所有我需要做的事情(偶尔得到你们这些可爱的人的帮助)。但我对普通的 TeX 和 TeX 的内部工作原理了解不多,而且我做的大部分工作都不需要知道它们。
但我希望学习更多,但如果没有真正对我有用的事情可做,我就无法获得动力。
所以我希望你们能对必须做的事情提出一些建议,这样我就可以了解需要做什么并去做。这对 TeX 社区来说确实有用,但足够简单,可以作为起点(尽管它可能具有挑战性;这就是重点)。
我还想了解更多关于 LaTeX 3 的信息,所以我想也许与 expl3 相关的东西会很好。即使是一个需要改进的函数,我也可以尝试一下。无论如何,有些东西让我在学习的同时感觉自己正在做一些有价值的事情。
更好的是,如果你们愿意的话,可以进行一系列渐进式任务,例如:
简单的东西:
- 写这个函数
- 修复此问题
- 记录此代码
更难的东西:
- 添加此功能
等等…
如果有一个需要完成的足够多的任务清单(即使它们是每个人都在拖延的那些烦人的部分),也许会有更多的人有兴趣解决它们,并且它会让人们更有兴趣学习东西,同时帮助当前的项目。
答案1
我也是同样的情况!
我一直在拼凑一个简单的包,可以声明和使用文本“样式”。
我为论文编写了一个相当强大的类(desert.cls
),但希望允许键值选项表现如下:
\documentclass[
style/footnote = {small,sans,FF0000},
style/chapter-name = uppercase,
style/source-code = \myfancymacro,
]{desert}
每种风格都是以逗号分隔的列表:
- 字体系列或形状;
- xcolor 颜色;
- 用户定义的宏;
- 大写、小写、句子大小写等
- 可能未来的字体和/或微字体选项
如果您有兴趣完成此操作并将其一起发送到 CTAN,请告诉我。这是我目前的尝试。
txtstyles.sty
\RequirePackage{xparse}
\RequirePackage{l3keys2e}
\RequirePackage{etoolbox}
\ProvidesExplPackage{txtstyles}{2022-02-02}{0.1}{Text styles}
\RequirePackage[
dvipsnames,svgnames,x11names,
hyperref
]{xcolor}
\RequirePackage{fontspec}
\RequirePackage{fontsize}
\RequirePackage{caption}
\RequirePackage{microtype}
%===================================================================
% text commands and aliases
%===================================================================
\NewDocumentCommand{\txtsub}{+m}{\textsubscript{#1}}
\NewDocumentCommand{\txtsup}{+m}{\textsuperscript{#1}}
\NewDocumentCommand{\txtuppercase}{+m}{\text_uppercase:n{#1}}
\NewDocumentCommand{\txtlowercase}{+m}{\text_lowercase:n{#1}}
% converts capital letters to small-caps but leaves lowercase
% Great for mixed-case acronyms like "ChEMBL", and acronyms no longer stand out
% https://tex.stackexchange.com/questions/39831/uppercase-smallcaps-with-latex-not-xelatex
\NewDocumentCommand{\txtuptosc}{+m}
{
\tl_set:Nn \l_tmpa_tl {#1}
\regex_replace_all:nnN
{ ([A-Z]+) }
{ \c{textsc} \cB\{ \c{lowercase} \cB\{ \1 \cE\} \cE\} }
\l_tmpa_tl
\tl_use:N \l_tmpa_tl
}
% Just for symmetry with \txtuptosc
\NewDocumentCommand{\txtalltosc}{+m}
{ \textsc{\text_lowercase:n{#1}} }
% Uppercase first character; lowercase the rest
\NewDocumentCommand{\txtsentencecase}{+m}
{ TODO }
% Uppercase first character and each first character after punctuation; lowercase the rest
% E.g. "\txttitlecase{grab a red one}" --> Grab A Red One
\NewDocumentCommand{\txttitlecase}{+m}
{ TODO }
\NewDocumentCommand{\txttomath}{+m}
{ \ensuremath{#1} }
%===================================================================
% main code
%===================================================================
% build up aliases for style commands
\prop_new:N \g_txtstyle_aliases
\prop_new:N \g_txtstyle_aliases_tmp
\prop_set_from_keyval:Nn \g_txtstyle_aliases_tmp
{
normal=normalfont,
rm=rmfamily, % families
roman=rmfamily,
sf=sffamily,
sans=sffamily,
tt=ttfamily,
mono=ttfamily,
md=mediumseries, % series - -medium
medium=mediumseries,
bf=bfseries, % series -- bold
bold=bfseries,
textbf=bfseries,
up=upshape, % shapes -- upright
upright=upshape,
it=itshape, % shapes -- italic
italic=itshape,
textit=itshape,
sl=slshape, % shapes -- slant
slant=slshape,
slanted=slshape,
textsl=slshape,
sw=swshape,
swash=swshape, % shapes -- swash
textsw=swshape,
sc=scshape, % shapes -- smallcaps
smallcaps=scshape,
textsc=scshape,
sub=txtsub, % sub/superscript
subscript=txtsub,
sup=txtsup,
superscript=txtsup,
upcase=txtuppercase, % lower/uppercase
uppercase=txtuppercase,
downcase=txtlowercase,
lowercase=txtlowercase,
uptosc=txtuppertosc, % fancy cases
alltosc=txtalltosc,
sentencecase=txtsentencecase,
titlecase=txttitlecase,
wee=scriptsize, % sizes -- script (avoid functional name)
weer=scriptsizer,
weerr=scriptsizerr,
weerrr=scriptsizerrr,
mini=footnotesize, % sizes -- footnote (avoid functional name)
minir=footnotesizer,
minirr=footnotesizerr,
minirrr=footnotesizerrr,
mid=normalsize, % sizes -- normal (just hate the suffix)
midr=normalsizer,
midrr=normalsizerr,
midrrr=normalsizerrr
}
% add the values themselves as keys
\prop_map_inline:Nn \g_txtstyle_aliases_tmp
{
\prop_put:Nnn \g_txtstyle_aliases {#2}{#2}
\prop_put:Nnn \g_txtstyle_aliases {#1}{#2}
}
\tl_log:n{\g_txtstyle_aliases}
% call \DeclareCaptionFont for all nonstandard options
\seq_new:N \g_txtstyle_caption
\seq_set_from_clist:Nn \g_txtstyle_capstyles
{ rm,sf,tt,up,it,sl,md,bf,scriptsize,footnotesize,normalsize,large,Large }
\prop_map_inline:Nn \g_txtstyle_aliases
{
\prop_if_in:NnF \g_txtstyle_capstyles {#1}
{ \DeclareCaptionFont{#1}{ \cs:w #2 \cs_end: } }
}
\msg_new:nnn{txtstyles}{notunderstood}{Command\ /\ name\ '#1'\ not\ understood\ while\ declaring\ style\ '#2'.}
\msg_new:nnn{txtstyles}{stylemissing}{Cannot\ use\ style\ '#1':\ it\ is\ not\ defined.}
\msg_new:nnn{txtstyles}{stylenotdefined}{Style\ '#1'\ is\ not\ defined;\ cannot\ renew.}
\msg_new:nnn{txtstyles}{styledefined}{Style\ '#1'\ is\ already\ defined;\ cannot\ define.}
\cs_new:Npn\notunderstooderr:n #1 { \msg_error:nnn{txtstyles}{notunderstood}{#1} }
\cs_new:Npn\stylemissingerr:n #1 { \msg_error:nnn{txtstyles}{stylemissing}{#1} }
\cs_new:Npn\stylenotdefderr:n #1 { \msg_error:nnn{txtstyles}{stylenotdefined}{#1} }
\cs_new:Npn\styledefderr:n #1 { \msg_error:nnn{txtstyles}{styledefined}{#1} }
% converts a single name, like "LARGE", \bf, or "red" to a command
\cs_new:Npn \convert_cmd:n #1
{
\cs_if_exist_use:cTF{#1}
{} % option 1: a command that starts with \
{
% options 2 (named alias) and 3 (color)
\prop_get:NnNTF \g_txtstyle_aliases {#1}
{} { \color{#1} }
}
}
% defines a new style as a list of commands (via \convert_cmd)
\NewDocumentCommand{\DeclareTxtStyle}{m >{\SplitList{,}}m}
{
\cs_gset:cpn{g_txtstyle_#1:n} {#1} {
\tl_new:N\mytl
\tl_set:Nn\mytl{#1}
\tl_map_inline:cn {##2}
{ \tl_set:Nn\convert_cmd:n{#1}{\mytl} }
\mytl
}
}
% related commands a la [New/Renew/etc.]DocumentCommand
\NewDocumentCommand{\NewTxtStyle}{mm}
{
\cs_if_free:cTF { g_txtstyle_#1:n }
{ \DeclareTxtStyle {#1} {#2} }
{ \styledefderr:n{#1} }
}
\NewDocumentCommand{\AliasTxtStyle}{mm}
{
\cs_if_exist:cTF { g_txtstyle_#2:n }
{ \cs_gset:cpn{g_txtstyle_#1:n} #2 }
{\stylenotdefderr:n{#1} }
}
\NewDocumentCommand{\NewAliasTxtStyle}{mm}
{
\cs_if_exist:cTF { g_txtstyle_#2:n }
{
\cs_if_free:cTF { g_txtstyle_#1:n }
{ \cs_gset:cpn{g_txtstyle_#1:n} #2 }
{ \styledeferr:n{#1} }
}
{ \stylenotdeferr:n{#1} }
}
\NewDocumentCommand{\RenewTxtStyle}{mm}
{
\cs_if_exist:cTF { g_txtstyle_#1:n }
{ \DeclareTxtStyle {#1} {#2} }
{ \stylenotdefderr:n{#1} }
}
\NewDocumentCommand{\ProvideTxtStyle}{mm}
{
\cs_if_exist:cF { g_txtstyle_#1:n }
{ \DeclareTxtStyle {#1} {#2} }
}
% Sets the text style (similar to \bfseries, etc.)
\NewDocumentEnvironment{TxtStyle}{m+b}
{
\cs_if_exist_use:cTF{g_txtstyle_#1:n}
{{#2}}
{ \stylemissingerr:n{#1} }
}{}
\NewDocumentCommand{\StyleTxt}{m+m}
{ \begin{TxtStyle}{#1} #2 \end{TxtStyle} }
main.tex
\documentclass{article}
\RequirePackage{txtstyles}
\begin{document}
\DeclareTxtStyle{sty}{large,red}
\StyleTxt{sty}{This text} was styled.
Done.
\end{document}