Tag Info

New answers tagged

3

For its internal purposes, bytefield changes the category code of & upon starting the environment. This change cannot affect the argument already absorbed by \bansen, so you have to do the category change beforehand: \documentclass{article} \usepackage{bytefield} \newcommand{\bansen}{% \begingroup\catcode`&=10 \banseninternal} ...


0

You have to say \makeatletter \newcommand{\submissionyear}[1]{\def\@mtsubmissionyear{#1}} \newcommand{\sijil}[1]{\def\@mtsijil{#1}} \makeatother because you want to use internal commands (with @).


0

I used any of the standard classes (article, book, report, scrbook etc. and memoir) and all them work with the \title{\color....} statement. I could imagine that some specific class has a problem with the \color statement itself, so \protect might help, but for this example, it's not necessary. As long as there is no MWE or further indication, what the ...


0

You didn't give minimal working example so it is hard to tell but, I think, that you are just mnissing the \usepackage command. To get a blue title the following works for me: \documentclass{article} \usepackage{xcolor} \begin{document} \title{\color{blue}Hello} \maketitle \end{document}


0

I'm sure there is a package for that, but here is a solution based on redefining the maketitle command (for the article class). Create a style file (I saved as titlecolor.sty') with the following content (I copied this from thebook.clsfile and add the\color` command to the title, you can change the format): \renewcommand\maketitle{\begin{titlepage}% ...


2

An expl3 way to do this could be: \usepackage{xparse} \ExplSyntaxOn \cs_new:Npn \mathfortyfive_maybe_define:Nn #1#2 { \cs_if_free:NT #1 { \cs_new_nopar:Npn #1 {#2} } } \cs_generate_variant:Nn \mathfortyfive_maybe_define:Nn { cn } \NewDocumentCommand \mymacro { mm } { \mathfortyfive_maybe_define:cn { #1 autorefname } { #2 } } \ExplSyntaxOff There may ...


2

Also, the LaTeX kernel provides \@namedef for this: \makeatletter \newcommand*{\mymacro}[2]{% \@namedef{#1autorefname}{#2}% } \maketatother Indeed, the task you want to accomplish is a pretty common one: just think of how labels for cross-referencing are defined. Caveat: In contrast with the \providecommand solution, \@namedef will silently overwrite a ...


4

\newcommand{\mymacro}[2]{%% \expandafter\providecommand\expandafter *\csname#1autorefname\endcsname{#2}%% } then if #1 is zzz \zzzautorefname will be defined.


4

You can correct the spacings with etoolbox: \documentclass{gsm-l} \usepackage[papersize={160mm,240mm},inner=20mm, outer=15mm, vmargin=15mm]{geometry} \geometry{includeheadfoot} \usepackage{fouriernc} \usepackage{esvect} \usepackage{amsmath,enumitem} \usepackage{remreset} \usepackage{etoolbox} \usepackage{pgf,tikz} \usetikzlibrary{arrows} \makeatletter % ...


1

While I strongly discourage the use of newcommands for such cases, here is a more-readable way of doing it: \documentclass[12pt,a4paper]{article} \usepackage{hyperref} \newcommand{\qqq}[1]{\section{Question}\begin{enumerate}#1\end{enumerate}} \newcommand{\exer}[2]{\section{Exercises}\begin{enumerate}#1\end{enumerate} \href{my.url.com/path/{#2}}{Take the ...


4

The names beginning with \end.... are reserved for implementing the end codes of environments, so you can not define \endexer with \newcommand. You could call the command \stopexer or \exerend or anything else that does not start with \end.


5

The first problem you have is that you cannot create a macro starting with \end... when using \newcommand. This check is defined inside the LaTeX kernel as part of an \@ifdefinable condition. To circumvent this you need to use TeX directives. That is, \def\endexer#1{<stuff>} rather than \newcommand{\endexer}[1]{<stuff>} Secondly, the ...


2

My possible solution uses the tocloft facilities to generate a \listof... for the enums and items counters (autodefined by \newlistof). In addition, \xapptocmd from xpatch writes the \listofenums and \listofitems entries by using \addcontentsline. There is one backdraw so far: It's not possible to define a title for the \listof... entry. ...


1

I've never done this with lists, but I've done it with drafts of textbooks in order to provide easy links from exercises to their answers in the back of the book. For me, I used the newfile package, which allowed me to essentially duplicate the TOC, LOT, and LOF mechanisms for exercises. For each exercise, I printed the exercise itself on the current page, ...


3

You could prefix the correct answer by * and test for it, using \CorrectChoice for this case and \choice for the others; then you can use the standard exam features for hiding or showing the correct choice: removing the answers option will hide the correct answers. \documentclass[ a4paper, addpoints, answers, 12pt ]{exam} ...


1

You could abuse xparse for this by assuming the first argument is correct and allowing a star * to indicate an other correct answer. By checking against all the arguments, you can toggle which are correct. Note that this solution is shaky: it will allow multiple correct answers in choices 2–5, but each of these will cause choice 1 to be incorrect. For ...


4

Assuming you want input syntax \unit{kg}{m} what you need to do is use the TeX primitive \futurelet to search for an upcoming {. If there is one, we can grab a (braced) argument, typeset it in math mode then loop. Note that this approach requires braces around each argument. \documentclass{article} \makeatletter \def\unit{% $% ...


4

The problem when you do \def\@unit#1 is that the argument will never be the brace, but all that goes from the open brace to the matching closed one and your test is never successful. You can do it with \futurelet, but you'll be tied to a very inflexible system of input. Here's an expl3 implementation that's possibly clearer than \futurelet. ...


1

Quoting from one of the comments: “Solutions with non-letter characters are welcome”. So, I present a solution that extracts arguments made entirely of letter (\catcode = 11) characters, up to, but not including, the first non-letter. In principle, the code could be adapted to include the ten digits 0…9 as well. This solution requires nothing more than ...


1

In the documents for my classes, I set lots of flags to either show answer or hide answers, to create a slightly different version of the document, for all sorts of purposes. I generally don't like having to go into the document and change something to create these modifications. Instead, I create a directory I call ./.design in which I place various files ...


4

A proper way is to use \@bsphack and \@esphack: \documentclass{article} \usepackage{xcolor} \newif\ifshowprivatecomments \showprivatecommentstrue \makeatletter \newcommand{\privatecomment}[1]{% \ifshowprivatecomments \textcolor{red!50}{#1}% \else \@bsphack\@esphack \fi } \makeatother \begin{document} This is text \privatecomment{This is a ...


5

You could do \newif\ifshow \showtrue \def\privatecomment#1{\ifshow#1\fi} but really it's simpler and more efficient to do \def\showtrue{\def\privatecomment##1{##1}} \def\showfalse{\def\privatecomment##1{}} \showtrue


5

A simple if switch without any frillz. \documentclass{article} \newif\ifshowmycomments \showmycommentstrue \long\def\privatecomment#1{\ifshowmycomments#1\fi} \begin{document} \privatecomment{Shows by default} \showmycommentsfalse \privatecomment{Turned off} \showmycommentstrue \privatecomment{On again.} \end{document}


3

Adding to what's already been said, while using xspace, I have discovered that if a macro which contains \xspace as its last argument is followed by text inside {}, then it does not insert a space between the two. In such a situation, one has to use the macro followed by an additional \ and then the text inside {}. For instance, if I have a macro defined as ...


1

It's not using a list mechanism at all just paragraphs, so add \setlength\parskip{5cm} to the definition and the paragraphs will be spaced out.


2

I tried to improve Gonzalo Medina's code to be able to use two-sided documents. The four aguments (the first three are optional and the last one is mandatory) are the same than in Gonzalo Medina's code. I have tried to do my best so that the pointer is facing the text wich was juste before \caution (this is the reason why my MWE is so long, I had to get ...


4

If the restriction that no assignments (in particular, no definitions) must intervene in the test for equality can be partially lifted, as one of the comments seems to permit, in the sense that they may be allowed in a “preliminary” phase in which one sets a “constant” name against which subsequent tests for equality will be made using expansion alone, the ...


10

Taking your requirements at face value, we can't use \pdfstrcmp or equivalent as it's not part of e-TeX (it's a pdfTeX primitive available in XeTeX under a different name and in LuaTeX using Lua emulation). What we can do is a token-by-token comparison of the \string versions of the two macro names. This will work provided there are no spaces in the names. ...


7

If \pdfstrcmp is allowed (or its friends in other TeX compilers like \strcmp in XeTeX), it's quite simple: Example for plain-TeX: \input pdftexcmds.sty\relax \catcode`\@=11 \long\def\someIf#1#2{% \ifnum\pdf@strcmp{\noexpand#1}{\noexpand#2}=0 % } % Testing \def\msg#{\immediate\write16} \someIf\foo\bar \msg{equal}% \else \msg{not equal}% \fi ...


6

No, you cannot compare two control sequence names in expandable way unless you turn them into strings. The available test is \ifx, which compares the meaning. This requires e-TeX, runs with pdftex, xetex and luatex: \input pdftexcmds.sty \catcode`@=11 \def\STRINGEQ#1#2{TT\fi \ifnum\pdf@strcmp{\detokenize{#1}}{\detokenize{#2}}=\z@ } \catcode`@=12 ...


2

The color specification in the argument to \colorbox should fully expand to a color name; since \IfEqCase does much work with its arguments and this work includes doing assignments, it can't be used in places where full expansion is needed. A better (and simpler) strategy is to say \colorlet{levelcolor1}{ForestGreen} \colorlet{levelcolor2}{CornflowerBlue} ...


2

The package you need is amsthm (besides the recommended amsmath). Add \usepackage{amsthm} and all will go flawlessly.


2

You can do so with the code as found at http://tex.stackexchange.com/a/245685/28093 \documentclass[margin=1cm]{standalone} \usepackage{amsmath} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{calc} %%% START MACRO FOR ANNOTATION OF TRIANGLE WITH SLOPE %%%. \newcommand{\logLogSlopeTriangle}[5] { % #1. Relative offset in x direction. ...


2

Using relative coordinates instead of absolute coordinates is the solution. Accordingly, rel axis cs is used instead of axis cs. It involves quite some math to derive an expression for \yCrel without using \yC, but this is the result (see code) and it works without giving the Dimension too large error. \documentclass[margin=1cm]{standalone} ...


6

In LaTeX the \par command gets redefined several times during a run over a document. For example, inside a tabular it does nothing: an input such as \begin{tabular}{l} \ttfamily\meaning\par \end{tabular} would print macro:->. (after the colon the parameter text is shown; after -> up to the period the replacement text is shown). This way, users ...


1

The easiest way to find what a command does is to create a minimal and run: \makeatletter\ttfamily \meaning\par \\ \meaning\@@par \\ \meaning\p@ As you go along studying the LaTeX2e kernel you can grow this minimal with notes etc. The best study source for coding LaTeX2e style packages and macros is the source itself, as well as packages. All these ...


1

As you say, you can only have 9 arguments here. So you have to think about some other approach which uses not more than 9 parameters per used command. You could, for example, define a command for each row of the matrix. To be honest, I do not see the advantage here, I would recommend to have dummy matrices in your preamble which you can copy where ever you ...


3

You have too deep expansion in two places: add \expandonce. First: \newenviron{solution}{}{\xappto{\temp@solnlist}{\expandonce{\solutionbody} {\@@par}}} % Second: \listxadd{\qaks@solutionlist}{% %noexpand so that I want it to expand later when typesetting the whole %solution list. But note that \temp@solnlist is expanded right here. ...


0

For further comparison, here is a solution using the gmp package to embed a Metapost graphic. Here, the use of PostScript is entirely hidden behind the MP language of course, so it might not meet the OP homework requirements. \documentclass{article} \usepackage[shellescape]{gmp} \newsavebox{\ringbox} \newcommand{\ringer}[1]{\sbox\ringbox{#1}% ...


2

You don't need the test for numeric, in my opinion. I suggest a different syntax: \der[<function>]{<variable>}[<order>] with two optional arguments; if you omit the first, you get the operator, otherwise the derivative; the second argument is the order of derivation. With xparse it's easy to do it; the first optional argument has empty ...


2

I think you want something like this (which actually tests for a sequence of digits resulting in >0 so don't use [000] ;-) \documentclass{article} \newcommand{\diff}[1][]{% \def\ArgI{#1}% \diffRelay% } \def\eatrelax#1\relax{} \newcommand{\diffRelay}[2][]{% \expandafter\eatrelax\ifnum0=0\ArgI\relax% is numerical % better: \and #1 is empty ...


2

The correct code seems to be \documentclass[margin=1cm]{standalone} \usepackage{amsmath} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{calc} \newcommand{\logLogSlopeTriangle}[5] { % #1. Relative offset in x direction. % #2. Width in x direction, so xA-xB. % #3. Relative offset in y direction. % #4. Slope ...


1

\pgfplotsextra is, roughly, the pgfplots command of the TikZ/PGF equivalent \pgfextra. There are two things interacting here. First of all, when it comes to path drawing execution, pgfplots is not TikZ for a very good reason. Because it has to create an axis based on the plotted entities such that the paths are tightly encapsulated by the axis limits, ...


2

This is not so much a solution as a demonstration. In the lower right corner are (\xmin,\xmax,\ymin,\ymax) computed without \pgfplotsextra and in the upper right corner with \pgfplotsextra. Using a calculator one can show thet e^\xmin=5 and e^\xmax=20,000, which correspond to the axis limits. \documentclass{standalone} \usepackage{pgfplots} ...


0

Some editors have a shortcut for inserting a % in every line of a marked text part. Apart from specific packages you could just define a simple command that throws away its argument (doesn't use it for something), like the following: \long\def\comment#1{} You can then insert it at the beginning of your text passage and add the closing bracket at the end. ...


3

A \cev command that seems to give good results on most letters and works correctly (apart a very small drift) in subscripts and superscripts. \documentclass{article} \usepackage{graphicx,accents} \makeatletter \DeclareRobustCommand{\cev}[1]{% \mathpalette\do@cev{#1}% } \newcommand{\do@cev}[2]{% \fix@cev{#1}{+}% ...


2

What you do with \foo[listofname={\listofmarxbrothersname},listext=mb,countername={mb}]{marxbrothers} is essentially \newlistof{\foocountername}{\foolistext}{\foolistofname} \newcommand\marxbrothers[1]{% \addcontentsline{\foolistext}{section}{\csname the\foocountername\endcsname~##1}% ...% } which is certainly not what you want, because ...


3

A function name should be of the form \<prefix>_<name>:<signature> where <prefix> is a string of letters, possibly preceded by __, and <name> is a string of letters and underscores that should remind the function's role. The <signature> is a string of letters among NnTFcofxVvwp, that should reflect the number of ...


2

The signature are the chars behind the colon: \your_special_function:Nnn has three arguments (N, n, n).


0

Not sure if this is what you want, in case comment under my answer. 12.5cm for the multicolumn goes out of the page so I reduced it to 7.5cm. If you want to leave the first cell of each row empty, then just delete "some text:" from the \newcommand. \documentclass{article} \usepackage{longtable} \newcommand{\newrow}[1]{ Some text: & ...



Top 50 recent answers are included