Hot answers tagged

9

Use \let\bulleto\bullet to preserve the old meaning before you use \renewcommand to redefine it. See also What is the difference between \let and \def?


7

Here is an example how to strip the last s using TeX primitives. The expandable macro \striplastS is created. \striplastS{texts} expands to text and \striplastS{text} expands to text too. \def\striplastS#1{\striplastSa{#1}#1\end s\end\eend} \def\striplastSa#1#2s\end#3\eend{\ifx\end#3\end#1\else#2\fi} %test: \message{\striplastS{text} \striplastS{texts}} % ...


7

Nasty trick! \begin{filecontents*}{\jobname.bib} @book{Schmidt.2013, author = {Schmidt}, year = {2013}, title = {Some Title} } \end{filecontents*} \documentclass{scrreprt} \usepackage[backend=biber,bibencoding=utf8,style=authoryear-icomp]{biblatex} \addbibresource{\jobname.bib} \newcommand\nocfspace{\renewcommand{\prenotedelim}{}} \newcommand{\cf}{\...


7

It is not that they are single letter particularly it is that they are used internally already in latex (and plain tex) most accent commands are single character \c, \r \v etc If you redefine these commands then you break accented letters even if they are input as characters via inputenc. \documentclass{article} \usepackage[utf8]{inputenc} \begin{document}...


5

You check for math mode and then use \mathpalette: \documentclass{article} \usepackage{amsmath} \makeatletter \newlength{\negph@wd} \DeclareRobustCommand{\negphantom}[1]{% \ifmmode \mathpalette\negph@math{#1}% \else \negph@do{#1}% \fi } \newcommand{\negph@math}[2]{\negph@do{$\m@th#1#2$}} \newcommand{\negph@do}[1]{% \settowidth{\negph@wd}{#1}...


5

There are two issues, really. The first is that it is an extremely bad idea to redefine basic TeX and LaTeX macros unless you absolutely know what you are doing. The second is that \; is not valid outside maths mode. Perhaps you want something like \documentclass{article} \begin{document} \newcommand{\drm}{\ensuremath{\;\mathrm{d}}} \drm \end{document} ...


5

Does it really have that? I couldn't find any instances via google except for this question. some journal classes, eg jss.cls have \newcommand{\ISBN}[1]{\def\@ISBN{#1}} which is much more reasonable, and I expect (hope!) the code you found was intended to be of that form, and is an error in the class. As shown, it's legal as Werner explains but it is a ...


4

It may provide an unconditional setting of content that has a one-time use. Consider the following example: \documentclass{article} % ============================================== % These is defined inside some class/style file \newcommand{\booktitle}[1]{\def\booktitle{#1}} \newcommand{\bookauthor}[1]{\def\bookauthor{#1}} \newcommand{\ISBN}[1]{\def\...


4

You can use the stringstringspackage by Steven B. Segletes: \documentclass{article} \usepackage{stringstrings} \usepackage{makeidx}\makeindex \begin{document} \newcommand{\indexMonster}[1]{% \testmatchingchar{#1}{$}{s} \ifmatchingchar \substring[q]{#1}{1}{$-1}\index{\thestring} \else \index{#1} \fi} \...


4

This solution uses xstring. Since there are some terrible monsters named albatross which are intesly feared, and you of course will be writing a lot about, I have also made a warning system for when the names of monsters have been changed. You can of course drop this if you feel like. If you want to override the test for monsters ending in s, simply add ...


4

It works if you write it this way: \newcommand\nand[2]{ \ifnum #1=#2 \ifnum #1=1 0 \else 1 \fi \else 1 \fi }


3

You could define your commands like given below: \newcommand{\FIRST}[1]{\gdef\@FIRST{#1}} \newcommand{\SECOND}[1]{\gdef\@SECOND{#1}} \newcommand{\THIRD}[1]{\gdef\@THIRD{#1}} \let\@FIRST\@empty \let\@SECOND\@empty \let\@THIRD\@empty Then later inside \maketitle you could replace \FIRST, \SECOND and \THIRD to \@FIRST, \@SECOND and \@THIRD respectively. Now ...


3

Even with your definition, you can use \mset R_2^1 and it will work as you want. In any case, in case you definitely want \mset{R_2^1} you can use \newcommand*\mset[1]{\overline#1} Which will work as you want, and it will even work with the \mset R_2^1 syntax.


3

You have more problems than you think of. \documentclass{book} \usepackage{etoolbox} \usepackage{imakeidx} \usepackage{fancyhdr} \makeindex[name=monsters,title=Monster index] \newcommand{\indexMonster}[1]{\index[monsters]{\stripfinals{#1}}} \newrobustcmd{\monster}[1]{#1\indexMonster{#1}} \makeatletter % Wipet's \newcommand{\stripfinals}[1]{\strip@final@s{...


3

lualatex solution \documentclass{article} \usepackage{luacode} \usepackage{makeidx} \makeindex \begin{document} \newcommand\myIndex[1]{\directlua{% mystr="#1" len=string.len(mystr) lastLetter= string.sub(mystr,len,len) if lastLetter=='s' or lastLetter=='S' then mystr=string.sub(mystr,1,len-1) end tex.sprint(mystr) }}% \newcommand{\indexMonster}[...


3

The file url.sty defines \path as follows: \@ifundefined{path}{\DeclareUrlCommand\path{\urlstyle{tt}}}{} In constrast, your (re)definition of \path does not use the \DeclareUrlCommand machinery. That's why it gets hung up on the "\}" substring in \path{C:\Code\Pre-requisite-Setup\}. (Note also that \path -- as defined in the url package via \...


3

Don't use a command with an argument -- this will always be difficult if catcode changes are involved. Better use the comment package: \documentclass{article} \usepackage{comment} \includecomment{instructor} %\excludecomment{instructor} \begin{document} bllb \begin{instructor} some text \catcode`\%=11 12 %% 13 \catcode`\%=5 \begin{verbatim} \section \end{...


3

You can do it, but I see no point: if the superscripts and subscripts should be outside the scope of the overline, place them outside the argument. Note that the k feature of xparse I'm using is classified as experimental and may disappear in the future (not really likely). \documentclass{article} \usepackage{xparse} \newcommand{\mset}[1]{\makemset#1} \...


2

Your assignments within the macro make it not expandable, and therefore you cannot nest it within other macros. If you go without the assignment, then you can nest them: \documentclass{article} \newcommand{\nand}[2]{% \ifnum #1=#2 \ifnum #1=1 0\else 1 \fi \else 1 \fi } \begin{document} \verb|\nand{0}{0}|: \nand{0}{0}% 1 \verb|\nand{0}{1}|: \nand{0}{...


2

This is my answer there, including the new command. You just have to \protect it: \documentclass{article} \usepackage{stringstrings} \usepackage{makeidx}\makeindex \begin{document} \newcommand{\indexMonster}[1]{% \testmatchingchar{#1}{$}{s} \ifmatchingchar \substring[q]{#1}{1}{$-1}\index{\thestring} \else \index{#1} ...


2

Here's a LuaLaTeX-based solution. It scans the input for instances of \mset{...} and rearranges the argument "on the fly", so that only leading single or multiple letters are part of the argument of \mset. Whitespace before or after the left-hand curly brace is allowed. \documentclass{article} \newcommand{\mset}[1]{\overline{#1}} \usepackage{luacode} \...


1

This isn't a great solution, but it works. A better but more complicated solution is in the edit below. Wrap each use of the \instructor{} macro that contains literal % characters in \catcode changes, e.g. in the original knitr code: \catcode`\%=11 \instructor{ <<>>= 1 %% 2 @ } \catcode`\%=5 A TeX wizard might know how to build that into the ...


1

\csdef etc. does infact allow numbers in 'command' names, but here's another way using \@nameuse and \@namedef from LaTeX2e core with expansion of the counter values -- I don't think that etoolbox is needed here for such an approach! \documentclass{article} \newcounter{cntLocalProblem} \newcounter{cntProblem} \newcommand{\fileprefix}{foo} \makeatletter ...


1

With etoolbox: \usepackage{etoolbox} \newcommand{\appendtolist}[2]{% \ifundef{#1}{\gdef#1{== \string#1 ==}}{}% \gappto#1{^^J#2}% } \appendtolist\mylistmacro{abc} \appendtolist\mylistmacro{def} \appendtolist\mylistmacro{ghi} \appendtolist\mylistmacro{lmn} \typeout{\mylistmacro} Output on terminal: == \mylistmacro == abc def ghi lmn More ...



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