# Tag Info

5

Note that AtBeginDocument does not in any sense find \begin{document}. the code for \begin{document} executes the command \@begindocumenthook if that is defined and \AtBeginDocument{...} just appends ... to the end of the hook macro so it gets executed when \@begindocumenthook is run. However if your list of tokens does not include {} groups you can use a ...

3

The \AtBeginDocument command doesn't work by searching: it adds code to a hook macro that is part of the internal code used to implement \begin{document} (actually the \document macro). What you need to do is set up appropriate hooks or simply append directly to the code you are using. The etoolbox package makes this easy \RequirePackage{etoolbox} ...

1

Something like this: \documentclass{article} \usepackage{amsmath} \newtoks\ilktoks \makeatletter \def\mtrx #1{\ilktoks{\mtrx@a{#1}}\@ifnextchar_{\mtrx@A}% {\@ifnextchar^{\mtrx@B}{\mtrx@end}}} \def\mtrx@A _#1{\ilktoks\expandafter {\the\ilktoks_{#1}}% \@ifnextchar^{\mtrx@AB}{\mtrx@endsub}} \def\mtrx@B ...

7

If the intention is to start a new group then you can use \newcommand{\openbrace}{\begingroup} or, more simply, just \begingroup To close the group, the corresponding macro is \endgroup

4

1

If a manual correction is enough... \documentclass[margin=1pt]{standalone} \usepackage{xcolor} % The actual \markup macro is a bit more complicated and contains an \if \newcommand\markup[1]{{\color{red}#1}} \begin{document} \begin{tabular}{| p{2cm} | c |} \hline p\{2cm\} & c \\ \hline \noindent\markup{1} & {2} ...

1

As suggested by egreg in the comments the verse environment did wonders for me :) It also lead me to the songs package which is quite handy.

3

LuaTeX is ideally suited for such macros. For example, here is an implementation in ConTeXt (which can be easily translated to LaTeX): \startluacode -- Function to choose amoung n alternatives function commands.ngettext(n, f, t) -- The function f should return an integer 1, 2, etc. -- The table t contains the corresponding list of plurals ...

1

A brutal-force solution for every word separately, here mysz. (Dwie mysze, hihi) \documentclass{article} \usepackage{polski} \usepackage[cp1250]{inputenc} \begin{document} \def\mysz#1{\ifcase#1 myszy\or mysz \or mysze (naprawdę istnieje liczba podwójna?) \or myszy \else myszy \fi} \mysz0 \mysz1 \mysz2 \mysz{126} \end{document} When mysz is replaced by ...

5

Just to show a version with build in scaling: \documentclass[a4paper]{memoir} \usepackage{mathtools} \DeclarePairedDelimiterX\brak[3]\langle\rangle{% #1 \delimsize\vert #2 \delimsize\vert #3} \begin{document} $\brak{e^+}{\mu}{e^-} \qquad \brak*{e^+}{\frac{\mu}{\sqrt{2}}}{e^-} \qquad \brak[\Big]{e^+}{\sum_i \mu_i }{e^-}$ \end{document}

6

You should use \brak{e^+}{\mu}{e^-} There're 3 different arguments, you can't separate them by commas.

10

You don't really want \xdef, because it can do really bad to your macros. In any case you don't really want to expand all the way through, which \xdef does. There are already several ways for appending tokens to a parameterless macro: \def\test{First -- Void1} \makeatletter \g@addto@macro\test{\ \& Second -- \href{http://www.wikibooks.org}{Wikibooks}} ...

6

\MakeUppercase converts the case of its argument to UPPER CASE. \documentclass{article} \let\CapLet\MakeUppercase \let\LowLet\MakeLowercase \begin{document} \CapLet{horse} and \CapLet{fish} \par \LowLet{HORSE} AND \LowLet{FISH} \end{document} It uses the TeX primitive \uppercase internally. A comparable \MakeLowercase exists.

2

egreg has already explained pretty well what is happening when beamer processes a frame. Besides moving the macro definition out of the frame environment, there is also the alternative to mark the frame as [fragile]: \documentclass{beamer} \usepackage{mathtools} \usepackage{calc} \begin{document} \begin{frame}[fragile] ...

4

The details are pretty involved. But basically beamer reads the contents of a frame environment as an argument and this process reduces a pair of ## into one #; but now your \newcommand is given in the argument to another command, so the # marks need to be doubled. The pairing means that you need four # characters to mean one of them. The solution is to do ...

14

\vspace{\fill} and \vfill are not exactly equivalent. They are if they appear between paragraphs, but not if they appear in a paragraph. \vspace{\fill} in a paragraph will add the filling vertical space below the line in which it eventually appears; \vfill ends the paragraph at the spot and adds the filling vertical space. Indeed \vfill is a TeX ...

10

Commands defined in that way are fragile, so you need \protect\testMe in the moving arguments, for instance the caption text. Let's see why. The argument to \caption needs to be massaged a few times, in particular it gets written to the .aux file for possible inclusion in the list of figures (or tables). When TeX does a \write operation, it expands ...

6


1

I'd go into a completely different direction. In your case there is no gain whatsoever in defining a complicated macro rather than typing more naturally $F_{a}^{b}[m]$ In case this is only an example of a more complex situation, I would recommend you a key-value syntax, that avoids chasing for tokens and distinguishing among different situations. This is ...

7

Since you only have one mandatory argument (and you are looking for ^ and _) I don't think xparse gains you a lot so i just use \@ifnextchar directly here. Also because you have m in a mandatory {} argument it should always be given so I changed \F to \F{} and added a test for the argument to be empty. (An alternative would be to make the argument optional ...

5

The following grabs multiple sub and superscripts. The argument in braces (which apparently is optional) should probably better be in [ ]. Code \documentclass{article} \makeatletter \def\F{% \let\f@sub\@empty \let\f@super\@empty \let\f@main\@empty \@ifnextchar\bgroup\f@catch@main\f@test } \def\f@catch@main#1{\def\f@main{#1}\f@test} \def\f@test{% ...

2

The following seems to work reasonably well with (at least) the limitation that it requires a space after the macro in order to work. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\F}{}{ \peek_charcode:NTF \c_group_begin_token {\renstar_F:w} {$F$} } \cs_new:Npn \renstar_F:w #1#2~ { ...

3

You should be able to remap keys as you please. It is easy on systems where xmodmap is available. (In this example, I'm using Ubuntu 12.10). We can, e.g., remap 'caps lock' to be 'backslash' using the following command. [EDIT: I forgot the caps lock requires special handling to avoid having it continue to switch between its normal toggling between caps ...

3

You can try changing your layout to Spanish. All the letter will be the in the same place (Spanish only has one extra letter: ñ, which will be where the ; is. The \ will be on your top left corner left to the 1. Take a look at this:

4

You can't do like that. The definition of \myParagraphs doesn't use #2; so \myParagraphs{myTextFile.tex}{2} becomes \input{myTextFile} and so TeX reads your file, where #2 is illegal. Here's a way: define a temporary macro to expand to the value of #2: \begin{filecontents}{myTextFile.tex} \ifthenelse{\second=1}{first paragraph}{} ...

2

AFAIK you cannot collect stuff that way. You need to store each paragraph in a macro with a name that can then be chosen via an option. That is how lipsum etc. works. It might be an idea to use etoolbox and its \csdef macro to build the macros and \csuse to execute them.

3

Test whether #5 is empty. If it is do nothing, otherwise print an itemize environment. \newcommand{\myentry}[5]{% \begin{tabular}{r | l} \begin{minipage}[c]{\narrowColumn} #1 \end{minipage} & \begin{minipage}[c]{\wideColumn} \textbf{#2}, \textit{#3}\\ #4 \if\relax\detokenize{#5}\relax\else \begin{itemize}[nosep] #5 ...

3

There are some flaws in your code. You defining the command \NewEntry with three mandatory arguments. Inside your document you are always call it with two arguments. The justification of the second argument fails. If you have a line break in your second argument the next line always starts left. Using the command printbibliography requires loading the ...

2

Here is a method the old-fashioned way, using macros with delimited parameters. \documentclass{article} \usepackage{amsmath} % for pmatrix environment \newtoks\asqltoks \makeatletter \def\gobtilundef #1\undef {} \def\matlabmatrix #1{\asqltoks{\begin{pmatrix}}\@asqlA #1;\undef;} % \def\@asqlA #1;{\gobtilundef #1\@asqlE\undef\@asqlR #1,\undef,} % update: ...

3

You don't have to do string replacement you can just define , and ; to do the right thing in pmatrix \documentclass{article} \usepackage{amsmath} \def\m#1{{% \mathcode\,"8000 \mathcode\;"8000 \begingroup\lccode\~\,% \lowercase{\endgroup\def~}{&}% \begingroup\lccode\~\;% \lowercase{\endgroup\def~}{\\}% \begin{pmatrix}#1\end{pmatrix}}} ...

3

Well, if you’re already using xstring, you could just try xparse. Apparently, pmatrix survives an additional \\ after the last line without adding an extra line (unlike the usual math environments). The additional & though has to be removed, this is done by \@gobblesecondoftwo. I have also included a solution that does use TeX’s delimited parameter to ...

5

Here's an implementation with expl3 functions: \documentclass{article} \usepackage{xparse,amsmath} \ExplSyntaxOn \NewDocumentCommand{\matlabmatrix}{m} { \asql_matlab_matrix:n { #1 } } \seq_new:N \l_asql_rows_seq \seq_new:N \l_asql_one_row_seq \tl_new:N \l_asql_matrix_tl \cs_new_protected:Npn \asql_matlab_matrix:n #1 { % clear the token list ...

3

This code should do what you want: \documentclass{article} \usepackage{xstring,amsmath} \newcommand*\mmm[1]{% \begingroup\expandarg \StrSubstitute{\noexpand#1},&[\result]% \StrSubstitute\result{\noexpand;}{\noexpand\\}[\result]% \begin{pmatrix}\result\end{pmatrix}\endgroup } \begin{document} $\mmm{a,b,c;d,e_{f,g},h;i,j_{1,e^n},k}$ ...

13


6

The l3regex package has both greedy and lazy regular expression searches. \documentclass{article} \usepackage{xparse,l3regex} \ExplSyntaxOn \NewDocumentCommand{\splitstring}{sm} { \IfBooleanTF #1 { \mafp_showstring:n { #2 } } { \mafp_splitstring:n { #2 } } } \tl_new:N \l_mafp_firstpart_tl \tl_new:N \l_mafp_secondpart_tl \tl_new:N ...

11


12

There is also a nice expl3 implementation \documentclass{article}% \usepackage{xparse} \ExplSyntaxOn \DeclareExpandableDocumentCommand \makealph { m } { \int_to_alph:n { #1 } } \ExplSyntaxOff \begin{document} \makealph{1} \makealph{5} \makealph{35} \end{document} As pointed out the definition of \makealph should be done by ...

16

Using pattern matching pdftex primitive \pdfmatch: \documentclass{article} % \makeatletter \def\cle@n@#1>#2{#2} \newcommand{\xsplitstring}[1]{% \ifnum\pdfmatch subcount 5 {((.+)[/])(.*)}{#1}=1 % First: \expandafter\cle@n@\pdflastmatch2, % Second: \expandafter\cle@n@\pdflastmatch3 % \else\fi } \makeatother % \begin{document} \xsplitstring{1/2/3} \par ...

11

For comparison, here is a LuaTeX solution (written in ConTeXt, but it should be relatively easy to translate to LaTeX) \startluacode commands.splitstring = function(s) local sep = "/" -- Split the string into fragments starting at / local fragments = string.split(s, sep) -- Reconstruct the pieces as desired local head = ...

13

You can also use LaTeX3: \documentclass[12pt,titlepage]{article}% \usepackage{xparse} \ExplSyntaxOn \tl_new:N \mafp_splitsting_tl \NewDocumentCommand \splitstring { m } { \tl_set:Nn \mafp_splitsting_tl { #1 } \tl_if_in:NnTF \mafp_splitsting_tl {/ } { \tl_reverse:N \mafp_splitsting_tl \exp_after:wN \mafp_splitstring:nn ...

10

The xstring package may be helful \input xstring.tex \def\splitstring#1#2{% \StrCount{#1}{#2}[\nbmatch]% \StrCut[\nbmatch]{#1}{#2}\strfirst\strsecond First : \strfirst\par Second : \strsecond } \splitstring{1/2/3}{/} \bye

4


6

You can do the following whereby I don't know what you want to achieve: \documentclass[11pt]{article} \makeatletter \def\acell#1{\gdef\@acell{#1}} \def\bcell#1{\gdef\@bcell{#1}} \def\zcell{% \ifx\@acell\@bcell yes\acell{a}\bcell{b}% \else no \fi% } \makeatother \begin{document} \begin{tabular}{ccc} \acell{A} & \bcell{A} & \zcell{} \\ ...

5

As commented, here a solution that uses \@ifnextchar. I also implemented checks against too many or too few arguments (or why are they provided by the user?). The \@ifnextchar(or its “very internal” big brother \kernel@ifnextchar) skips spaces which results in removed spaces in the third and fourth example. Code \documentclass{report} ...

7


1

You've not given us much to go off of, but here's something that seems to implement what you want while being fed a comma separated list (in lieu of passing a variable number of arguments). \documentclass{article} \usepackage{xparse} \newcounter{myargcounter} \ExplSyntaxOn \clist_new:N \l_myvararg_parameters_clist \tl_new:N \l_myvararg_current_item_tl ...

6

You have to expand extraticksmwe first. This can be achieved by \edef\x{\noexpand\begin{axis}[ ytick={0}, \extraticksmwe ] } \x However this isn't a nice solution. It also doesn't expand \extraticksmwe only once. I suggest to use \pgfplotsset inside your new defined command and call it before the environment axis starts: ...

1

You need two # characters (using only one # in the defining part will be incorrect since \resumestyle has no arguments): \documentclass{report} \usepackage[parfill]{parskip} \usepackage[explicit]{titlesec} \newcommand\resumestyle{% \titleformat{\subsection}{\large\scshape\raggedright}{}{0em}{##1}[\titlerule] } \begin{document} \tableofcontents ...

0

Use macro with {} solves the problem. \documentclass[11pt, oneside]{article} \newcommand{\abc}{$abc$} \begin{document} Word spacing \abc{} is correct now. Within brackets: (\abc{}). \end{document}

6

A stable way to exchange symbols is to change the fontencoding or to reencode the font. A simple example \documentclass{article} \begin{document} \newcommand\censor[1]{\fontencoding{OMS}\selectfont #1} \censor{Censored} \end{document} With lualatex it will in the future (when the interface is more stable) be probably be possible to create virtual ...

Top 50 recent answers are included