百度 在规模上台阶的基础上,按照“质量第一”的原则,上海国资委提出,2018年要确保发展速度不低于全市经济增速,质量效益继续高于全国国有企业平均水平。
{macros} is for questions specifically concerning TeX's macro processor. Note that, because TeX uses macros ubiquitously, most questions about code that uses macros are not looking for information about how macros work, and so are not appropriate for this tag.
22 questions from the last 30 days
3
votes
4
answers
339
views
Parsing \def patterns with braces
See MWE:
\documentclass{article}
\def\test hello#1{End}{#1}
\begin{document}
\test helloworld{End}
\end{document}
I would like to parse a pattern with braces in \def. How can I achieve that? ...
6
votes
3
answers
321
views
How can I automatically replace curly braces { and } in LaTeX macro arguments—e.g., in math formulas—for label generation?
I want to automatically "sanitize" arbitrary LaTeX math formulas (such as \mathcal{P}(A)) into a string that can be used as a label, by replacing all curly braces { with e.g. Lp and } with ...
4
votes
5
answers
243
views
How to \input file as arguments?
Background
I have a file QA.tex whose entire content looks like:
{Question}{Answer}
I would like to include this file into a document, but parse for only the Question part. My attempt at a solution (...
8
votes
2
answers
231
views
Customized alignment environment with indentation effect
I have a tex file
\documentclass{article}
\usepackage{amssymb,mathtools}
\mathtoolsset{showonlyrefs}
\begin{document}
\begin{align}
U_{t}^{r, x, \xi + h \eta} (y) & = \begin{aligned}[t]
& \...
6
votes
3
answers
184
views
Create string expansion in a single command
I am uncertain of what terms to search for to ask this question, but my goal is something along these lines:
\documentclass{article}
[\mycommand definition]
\begin{document}
1: \mycommand{a,b}
...
2
votes
3
answers
171
views
\def : How is the \verb=\verb= command defined?
\def : How is the \verb command, e.g. in \verb=\verb=, defined?
I'm not asking about \verb as such, but as an example how to \def something like that, a command with arguments encapsulated in brace-...
3
votes
2
answers
129
views
Define command valid only for a specific environment in expl3
I am defining an environment myenv using expl3 syntax.
\ExplSyntaxOn
\NewDocumentEnvironment
{ myenv }
{ }
{ }
{ }
\ExplSyntaxOff
(Should I use NewEnviron here instead of ...
2
votes
3
answers
121
views
Use of l3keys to collect optional arguments of `\NewDocumentCommand`
I am trying to understand how to use xparse to specify arguments to \NewDocumentCommand.
I need need to make a command which accepts a bunch of optional arguments in addition to a mandatory argument.
...
5
votes
2
answers
108
views
listings' morekeywords=[...]{...} in a custom command doesn't work
With listings, it is easy to define new languages with own keywords:
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstdefinelanguage{mylang}{%
morekeywords=[1]{foo},% numeric ...
2
votes
2
answers
110
views
Macro Definition Outside Current Group
If you use \gdef you can define stuff at the global scope. However, how can you define/overwrite a macro at the scope outside the current group but inside the parent group? I think I can probably ...
3
votes
2
answers
116
views
How to check if a macro exists when its name is constructed from a user-defined macro in LaTeX?
Problem
I'm writing a LaTeX macro system to manage acronyms in Overleaf, and I need to dynamically check whether a macro like \acronym@CH@used exists. The acronym key (e.g., CH) is stored in another ...
3
votes
1
answer
80
views
Creating a macro out of a tabulararray command
I would like to define a command that changes the background color of a specific table cell.
The following minimal working example (MWE) does not work as intended.
How can I properly define a macro ...
2
votes
2
answers
87
views
Make a modification of aligned environment into a separate command
I have a tex file (taken from David Carlisle's answer):
\documentclass{article}
\usepackage{etoolbox,amsmath}
\makeatletter
\patchcmd{\start@aligned}
{{}}
{\align@prercellhook}
{}{\errmessage{...
3
votes
1
answer
89
views
Command for computing binomial coefficients
Consider the following MWE:
\documentclass{article}
\newcommand*\binomCoef[2]{\fpeval{fact(#1)/(fact(#2)*fact(#1-#2))}}
\begin{document}
\binomCoef{5}{2}
\end{document}
The above example does ...
0
votes
1
answer
61
views
Simpler approach to change 1 line in the internal of aligned environment
I have a macro taken from this answer:
\documentclass{article}
\usepackage{mathtools}
\makeatletter
\def\align@prercellhook{{}}
\renewcommand{\start@aligned}[2]{%
\RIfM@\else
\...