Tag Info

Hot answers tagged

18

A macro is any control sequence (or active character) defined with \def, \gdef, \edef or \xdef. TeX macros support up to nine arguments, which contradicts your statement about it not having the notion of arguments to control sequences. The most common usage of arguments is in the “undelimited” form; say that you do \def\foo#1{--#1--} so \foo takes an ...


13

{} have two distinct uses in TeX, as grouping and to delimit macro arguments (when they do not form a group). Ignoring latex specifics and tests that make the argument optional, then \foo[arg1]{arg2}{arg3} is defined in tex primitives as \def\foo[#1]#2#3{something using #1, #2 and #3} so a use such as \foo[abc]{xyz}{123} then #1 is abc as the ...


8

True, only a single argument is given to \mathpalette within the \raisemath macro. The second argument to \mathpalette is grabbed from the remainder of the input stream. Here's a smaller example exhibiting the same setup: \documentclass{article} \newcommand{\abcd}[1]{\defg{#1}} \newcommand{\defg}[2]{#1-#2} \begin{document} \abcd{1234}{5678} \end{document} ...


6

etoolbox provides exactly this functionality via \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}, where it searches for <search> in <cmd> and replaces it with <replace>, executing <success> if the search-and-replace was successful, otherwise <failure>. The following uses an elementary ...


5

book, report and article are all generated from the same source (classes.dtx) and the differences that you mention are essentially the only differences there are. If they were no such differences then essentially there would only be one standard class. By design, article omits the \chapter level, to make it slightly easier to combine articles into a report ...


5

\documentclass{article} \newcommand{\myF}{\textit{f}} \newcommand{\myA}{\textit{a}} \newcommand{\yourF}{\begingroup\itshape f\endgroup} \newcommand{\yourA}{\begingroup\itshape a\endgroup} \begin{document} \myF\myA \yourF\yourA \textit{fa} \end{document}


4

Here is a solution that should cover most of the cases. First, I defined \C to simply set the \parindent to 0 for testing purposes. Then the basic idea is to delay the execution of \C until the begin of the document using the standard interface command \AtBeginDocument. Inside of it the conditional testing is done. When \ifC is set to true it will actually ...


4

The simplest method offered by LaTeX is the \verb macro and the verbatim environment. So for example you can write \verb|print($hello)| and obtain print($hello). Note that instead of regular brackets, \verb's argument is delimited by whichever character you put right after it. This allows you to avoid escaping the delimiters by just choosing a delimiter that ...


4

You can use \surroundwithmdframed[<options>]{<environment>} A complete example: \documentclass{article} \usepackage{listings} \usepackage{xcolor} %custom colours \usepackage[framemethod=tikz]{mdframed} %nice frames \definecolor{light-gray}{gray}{0.95} %the shade of grey that stack \surroundwithmdframed[backgroundcolor=light-gray, ...


3

keyval parsers typically don't expand the arguments (otherwise things like font=\small would blow up badly as \small would expand too early. so the simplest thing is to use \newenvironment{sss}{% \begin{itemize}[label={$\bullet$},topsep=0mm, parsep=0mm,% leftmargin=3mm,rightmargin=0cm,labelwidth=5mm,labelsep=3mm% ]} {\end{itemize}} \begin{sss} \item gugus ...


3

This answer actually doesn't answer your question which is about a command / mechanism / programming-trick that can be issued in the body of a document in order to affect how things get defined whose definition-texts occur in the preamble of the document. Your request is due to the unwillingness to scroll between the preamble and, e.g., the middle of a ...


3

I had my answer from August 24 deleted: It actually did not handle the request "if edition = 40,60,80,100,200,...1000 there is also prefix me-". Instead it handled the request "if edition > 21 and natural numbers k < 10 and l exist so that edition = k*(10^l), then there is also prefix me-". Thus, e.g., cases edition=30,50,70,90 were treated ...


2

MWE \documentclass{article} \makeatletter \newcommand\@mytitle{} % create macro for title \newcommand\mytitle[1]{\renewcommand\@mytitle{#1}} \newcommand\@mythanks{} % create macro for thanks note \newcommand\mythanks[1]{\renewcommand\@mythanks{% \gdef\@thefnmark{*}\@footnotetext{#1}} } \newcommand\@myauthor{} % create ...


2

If you have to set existing TikZ keys with the parser then you can use style args. If you need a custom code to be executed then you can also use code args and proceed from there. For the specific example, a possible way to do it: \tikzset{angles/.style args={#1,#2}{start angle=#1, end angle=#2}} \def\MyCircle[#1]#2{\draw #2 arc [#1];} ...


1

\newif\ifC \def\C{\ifC{your definition of C} \else \fi} And now you activate your command setting \Ctrue and desactivate, setting \Cfalse.


1

You need to insert the uppercasing into the result of \ac, but \ac does not work by expansion so \expandafter does not help. (If it had worked by expansion, your expression would still have been wrong as it passes \empty to \MakeUppercase) \documentclass[a4paper, 10pt]{report} \usepackage[utf8]{inputenc} \usepackage[printonlyused]{acronym} ...


1

Usually a key value parser needs to see the syntax characters = and , directly. Therefore, the macro \sss should be expanded once. This can be done with lots of \expandafter: \expandafter\begin\expandafter{\expandafter i\expandafter t ...\expandafter}\expandafter[\sss] or the whole expression can be expanded as macro: \edef\next{% ...


1

Box the listing before using it in the argument for \node: \documentclass{beamer} \usepackage{tikz} \usepackage{listings} \newcommand{\rednode}[1]{ \node[draw=red]{#1}; } \newsavebox\mybox \begin{document} \begin{lrbox}{\mybox} \begin{lstlisting} int main() { printf("Hello World\n"); } \end{lstlisting} \end{lrbox} \begin{frame}[fragile] ...


1

The simplest is to use the concept of delimited macros: this is not widely documented in LaTeX manuals, but LaTeX is built upon the TeX macro language which allows this functionality. However doing exactly as you want would be problematic (we don't want to change the catcode of the braces), thus, if you accept to delimit the optional part in the following ...


1

Control sequence approach As far as you asked about a macro here is a solution using delimited arguments (similar to @jfbu's solution) with a canonical macro introduced through the escape character \, that incorporates your syntax design: \documentclass{article} \newcount\switch \switch=0 \def\maybehide#1{\maybehidei#1} \def\maybehidei L #1 ...



Only top voted, non community-wiki answers of a minimum length are eligible