Tag Info

New answers tagged

2

You don't want a command name for the name of an environment. Just the name is fine. So, you can do this: \documentclass{article} \usepackage{amsthm,environ} \renewcommand\newtheorem[2]{% \NewEnviron{#1}[1]{% ##1 : \BODY }% } \begin{document} \newtheorem{acorns}{oaks} \begin{acorns}{trees} leaves and things \end{acorns} \end{document} ...


2

As you are doing inside an environment you need to define \counterIDX "globally" by using \gdef: \documentclass{memoir} \usepackage{totcount} \newenvironment{passagequestions}{% This does not work \gdef\counterIDX{passagecounterX}% \newtotcounter{c\counterIDX}% \total{c\counterIDX}% }{% } \begin{document} ...


8

The sequence \renewcommand{\twocolumn}{\twocolumn[{} would define a commmand \twocolumn that - among other things - would call itself. You would get some sort of recursive loop where compilation might terminate with an error message TeX capacity exceeded or the like when during recursion too many opening brackets and opening braces got accumulated. ...


2

One possible work around is to use a temporary file. First you need a macro to write to the file (\jobname.tmp was used here) and read it twice using the regular and the listing input commands: \usepackage{listings} \newwrite\tempfile \newcommand{\example}[1]{ \immediate\openout\tempfile=\jobname.tmp \immediate\write\tempfile{#1} ...


5

You should define a set of custom markup commands (see [1], [2]) for those fraction types, where you employ the xcolor package and the \prescript command from mathtools to do the needed formatting: \documentclass{article} \usepackage{mathtools,xcolor} \newcommand{\coloredfrac}[3][red]{% \frac{\color{#1}#2}{\color{#1}#3} } \newcommand{\ampfrac}[3]{% ...


1

Do you perhaps mean something like "highlight" by "amplify"? Anyway, I think \newcommand{\colorfrac}[3][red]{\frac{{\color{#1} #2}}{{\color{#1} #3}}} would suit your purpose. \colorfrac{1}{2} would give a red '1/2' and \colorfrac[green]{1}{3} a green one (needs the color package). Edit As an answer to your comment: Of course you could, ...


3

Here is a solution \documentclass{article} \usepackage{xcolor} \begin{document} \[\raisebox{\baselineskip}{4)}\frac{1}{2}=\frac{\textcolor{red}{1\cdot4}}{\textcolor{red}{2\cdot4}}=\frac{4}{8}\] \[\raisebox{\baselineskip}{4)}\frac{1}{2}=\frac{\textcolor{red}{1\cdot4}}{\textcolor{red}{2\cdot4}}=\frac{4}{8}\] \end{document}


1

The interface is already there, just use a c type argument instead of N: \documentclass{article} % Module named foo ;-) \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\foo}{m}{% \cs_new:cn {foo_#1:}{Hello ~ World} } \NewDocumentCommand{\foocall}{}{% \foo{start} % define \foo_start: \foo_start: } \ExplSyntaxOff \begin{document} \foocall ...


4

The definition mangling should probably be really constrained to the programming (expl3) layer with just the top level "latex2e" interface defined via xparse \NewDocumentCommand, also it is clearer in l3 if you define the commands first taking a normal \zzzz argument then the \expandafter\...\csname idiom is pre-packaged as "define a c variant" so... ...


4

I am not entirely sure that I understood what you want. However, your MWE can easily be achieved with xparse and its v type argument: \documentclass{article} \usepackage{qrcode,xparse} \NewDocumentCommand{\script}{v}{% \texttt{#1} \qrcode{#1}% } \begin{document} \script{test} \script{&$\#$} \end{document} Keep in mind, though, that now since now ...


3

You will have to expand the optional argument in order for \Y{<x>} to appropriately be seen as width=<x>\textwidth. Here are a number of ways to achieve this: First approach: An indirect way of expanding the optional argument (and possibly the mandatory one, depending on the usage). \documentclass{article} \usepackage{graphicx} ...


6

\documentclass{article} \newread\myread% Get a file handle grip, call it myread \newcommand{\openandtypeset}[1]{% \IfFileExists{#1}{% Check first \openin\myread=#1 % Open the file from #1 \begin{itemize} \loop \read\myread to \localvariable % Read line content to `\localvariable` \ifeof\myread % Is it at the end of the file -> localvariable is ...


0

A preliminary solution, not finished so far! \documentclass{book} \usepackage{etoolbox} \usepackage{xparse} \newcounter{sectionlevel} \makeatletter \NewDocumentCommand{\currentdepth}{sO{}m}{% \IfBooleanTF{#1}{% }{ \ifnum\value{sectionlevel} = -1 \part[#2]{#3}% \else \ifcase\value{sectionlevel} \chapter[#2]{#3} \or ...


3

Here is the xparse style of defining a command with optional argument, here with default empty optional argument. \documentclass[11pt,notitlepage]{article}% \usepackage{xparse} \usepackage{graphicx} \NewDocumentCommand{\includegraphicsX}{O{}m}{% \ifdefined\HCode \includegraphics[#1]{#2.eps} \else% \includegraphics[#1]{#2.pdf} \fi% } ...


7

Use \newcommand\commandname[2][]{<code>} for standard \commandname[<optional arg>]{<required arg>} syntax. \documentclass[11pt,notitlepage]{article}% \usepackage{graphicx} \newcommand{\includegraphicsX}[2][] {% \ifdefined\HCode \includegraphics[#1]{#2.eps}% \else \includegraphics[#1]{#2.pdf}% \fi } \begin{document} ...


4

This part of etoolbox is rather tricky, but not really complicated, once one gets the idea. When LaTeX executes \usepackage, the named file is loaded and @ is considered as a letter, which makes it possible to use it in macro names. The etoolbox package needs to change category codes in certain parts of it, so it wants to be sure to restore those settings ...


4

You can do it with regular expression, after checking the argument is blank: if the argument matches just a token or a token followed by a _ and a subscript, then use no parentheses. \documentclass{article} \usepackage{amsmath} \usepackage{expl3,xparse,l3regex} \DeclareMathOperator{\fvop}{fv} \ExplSyntaxOn \NewDocumentCommand{\fv}{m} { \fvop ...


3

The concept of “single symbol” is somewhat vague: I can suggest an exact test as to whether the argument is, or is not, a single token. \documentclass{article} \makeatletter \newcommand*\IsOnlyOneToken[1]{% TT\fi \@IsOnlyOneToken#1\@@@ } \@ifdefinable\@IsOnlyOneToken{\def\@IsOnlyOneToken#1#2\@@@{% \ifx\@empty#2\@empty }} \makeatother ...


1

With xstring package you can retrieve the length of a string: \documentclass{article} \usepackage{xstring} \usepackage{ifthen} \newcommand\fv[1]{% fv~% \ifthenelse{\equal{#1}{}}{}{% \StrLen{#1}[\mylen]% \ifthenelse{\equal{\mylen}{1}}{#1}{(#1)}% }% } \begin{document} \fv{e}\par \fv{e1 e2} \end{document}


2

The \IfSubStr macro from xstring can look for white space characters (well, blanks) between a string. However, this is not failsafe. \documentclass{article} \usepackage{xstring} \usepackage{ifthen} \usepackage{mathtools} \newcommand{\parens}[1]{ \ifthenelse{\equal{#1}{}}{}{(#1)} } \newcommand{\myarg}{e_{1} e_{2}} \newcommand{\myotherarg}{e_{1} } ...


4

\vbox doesn't start a paragraph: \newcommand{\CurlyBrackets}[1]{% \leavevmode\vbox{ \hbox{$\left\{\begin{tabular}{@{}l@{}}#1\end{tabular}\right\}$} }% } Full example \documentclass{article} \usepackage{gb4e} \noautomath \newcommand{\CurlyBrackets}[1]{% \leavevmode\vbox{ ...


2

I can't explain the behavior, but taking out \vbox and \hbox from the definition of \CurlyBrackets gives the right result. \documentclass{article} \usepackage{gb4e} \noautomath \newcommand{\CurlyBrackets}[1]{% $\left\{\begin{tabular}{@{}l@{}}#1\end{tabular}\right\}$ }% \begin{document} \begin{exe} \ex[\#]{\CurlyBrackets{A cat\\Seven dogs\\Mary} ...


4

I’m adding this answer only to justify my assertion that the present question is “somehow related” to How can I check whether two control sequences have the same name? (see the comments). Werner’s solution is great, but it has a slight drawback and a characteristic that, depending on what you want to do, can turn out to be a useful feature, or not. The ...


3

If the containment macro doesn't do anything special (that would survive a group), you can set the contents in a box. This allows you to test for something without anything being printed: true false \documentclass{article} \def\somecontrolseq{\macro{silly} text} \def\macro#1{some #1} \newif\ifmacroexists % ...


6

Luckily I discovered that the two problems mentioned in the OP are really the only ones and that they are solvable straight forward, after(!) trying out lots of other things :) The expansion problem is solved by a simple \expandafter "before" detokenizing the result (i.e. \detokenize\expandafter{\somecontrolseq}), which again solves the problem of the ...


0

I took Martin’s answer to a related question and simplified it a bit: With this code \documentclass{article} % next word parser, based on http://tex.stackexchange.com/a/11925/15107 \makeatletter \def\consumenextword#1{% \begingroup \let\@cmd#1% \def\@selectedword{}% \consumenextword@ } \def\consumenextword@{% ...


8

For a normal user, this is probably the easiest to understand \usepackage{etoolbox} \newcommand{\CommandA}{% \hspace{5mm}% } \newcommand{\CommandB}{% \vspace{5mm}% } \newcommand\C[1]{% \csuse{Command#1}% } \csuse builds a macro name, and calls it


0

Using ampersand replacement=\& seems the best strategy; however, I recommend you to give tikz-cd a try: \documentclass[tikz,border=10pt]{standalone} \usepackage{tikz-cd} \begin{document} \begin{tikzcd}[row sep=2em,column sep=2em] A \arrow[dr] & B \\ C & D \end{tikzcd} \end{document}


3

The problem arises from the use of & in the argument, which is problematic since they are a special character and PGF wants to treat them in a special way. A solution could be to use environments (which I find nicer anyway) and a trick to avoid needing an argument: \documentclass[tikz,border=10pt]{standalone} \usepackage{tikz} \usetikzlibrary{matrix} ...


10

\setlength{\topmargin}{#1 - 1in - \voffset - \headheight - \headsep} is an infix expression using syntax implemented by the calc package that you have loaded that defines \topmargin to be the fixed result of that expression at this point. \parskip=12 pt plus 0 pt minus 0 pt is a primitive skip assignment which would be better written as ...


2

Here's a TeXstudio macro that I use for exactly the purpose you mention: %SCRIPT txt = cursor.selectedText() editor.write("{"+txt+"}") cursor.clearSelection() One you have added this in the Edit Macros window (I used "Braces Around Text" as the Name and left the other fields blank), you can assign it a keyboard shortcut in Configure TeXstudio | Shortcuts. ...


2

enumitem has always met my needs for lists. However, I'm not sure it is the best option here. multienum seems designed to do just what you want. It provides an environment multienumerate within which you can use commands such as \mitemx{} to define a line with a single item, \mitemxx{}{} for a line with 2 and so on. You can also say something like ...


1

Here is a solution using the macros from mathtools and xparse. I define a \spr command with two arguments in one, separated by a comma. if one of the arguments is empty, it is replaced with a dot. To have variable sized parentheses or middle delimiter, use \spr*. You also can fine-tune the size of the delimiters with an optional argument, which will be one ...


1

Assuming I understand the question, a variable-sized pipe (i.e. |) can be obtained by replacing | with \middle|. Here is a MWE using \dfrac: \documentclass{article} \usepackage{amsmath} \newcommand*{\spr}[2]{\left(\,#1\,\middle|\,#2\,\right)} \begin{document} \( \spr{\dfrac{x}{y}}{z} \) \end{document} Notice that your definition of \spr forgot to ...


1

The enumitem package version 3.0 provide inline lists (horizontal lists), for their use just add inline in the options when calling the package, this provides the environments enumerate*, itemize* and description* they can be used as follows \documentclass{article} \usepackage[inline]{enumitem} \newcommand{\inline}[1]{\stepcounter{enumi} \def\c{\theenumi} ...


2

The problem Mico points out can be solved in @cfr's solution just by using LuaTeX or XeTeX. If one is bounded to pdfTeX engine, a possible solution is to use the amazingly powerful l3regex package. Edit: As egreg pointed out, I didn't know that there were so many multibyte prefixes. \documentclass{scrartcl} \usepackage{xparse,l3regex} ...


2

Even though the OP has stated that he/she isn't interested in a LuaLaTeX-based solution, others may still value having such a solution. :-) The following solution works with strings of UTF8-encoded characters. Because ASCII-encoded characters are automatically UTF8-encoded, the solution also works with ASCII-encoded strings. % !TEX TS-program = lualatex ...


2

Presumably there's an excellent reason not to use l3 syntax because egreg has not written an answer. Also note: I do not know what I'm doing. Caveat emptor... The expl3 package is used to enable l3 syntax. (The LaTeX equivalent of the latest thing since sliced bread.) xparse is used to easily define a starred form of the command which excludes spaces ...


2

A wild guess: you want that \Numbers{c3} defines a macro \Nbc that stores a random number in the specified range, with three decimal digits, an integer if no number is specified. Here's an expl3 implementation that relies on pdflatex for generating random numbers. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\Range}{mm} ...


1

The command \newcommand{\numchars}[1]... works well, but I encountered some issues with \stringlength in the stringstringspackage. It seems like it has a limit of 500 on the number of characters, returning zero if you go above that. For example, the code: \documentclass[11pt]{amsart} \usepackage{stringstrings} \newcommand{\numchars}[1]{\noindent The string ...


1

Writing the new command as Nb\Letter is not the standard way, \gdef expects a \name and not name\Letter. So I defined \Nba as \def\Nba{Nb\Letter}. \documentclass[10pt,a4paper]{article} \usepackage{tikz,xstring} \pgfmathsetseed{\number\pdfrandomseed} \def\Range#1#2{% \xdef\NbMin{#1}% \xdef\NbMax{#2}% } \def\Numbers#1{% \foreach \i in {#1} ...


6

You can do this with \newminted command \documentclass{article} \usepackage{minted} \newminted[lstlisting]{scala}{} \begin{document} \begin{lstlisting} #include <stdio.h> #define N 10 /* Block * comment */ int main() { int i; // Line comment. puts("Hello world!"); for (i = 0; i < N; i++) { puts("LaTeX is also ...


3

Since there are some commands using expex package I don't understand I provided some dummy commands. The relevant question is the argument #5, which can be empty. One solution is to use \ifblank{} from etoolbox or an optional argument, best defining the command with \NewDocumentCommand. \documentclass{article} % A lot of dummy commands ...


2

To find definitions, you may use latexdef command. Example (using the -s option to try to show the original source code of the command definition and the -c option to load given class): latexdef -s -c article @makefntext produces: % article.cls, line 619: \newcommand\@makefntext[1]{% \parindent 1em% \noindent ...


2

It's really easy with xparse: \usepackage{xparse} \NewDocumentCommand{\ocite}{om}{% \IfNoValueTF{#1} {% no optional argument in the input \cite{#2}% } {% optional argument has been given #1,~\cite{#2}% note the tie }% } The list of arguments, instead of being a number, says o for an optional argument without a default ...


5

You can test if the optional argument is empty. How to check if a macro value is empty or will not create text with plain TeX conditionals? gives several possible ways how to do that. I picked one here: \documentclass{article} % traditional solution: \newcommand*\mycommand[2][]{% \if\relax\detokenize{#1}\relax \else #1,\nobreakspace \fi ...


6

With a little help of grep: The standard classes define this command: For example article.cls Within \maketitle: \long\def\@makefntext##1{\parindent 1em\noindent \hb@xt@1.8em{% \hss\@textsuperscript{\normalfont\@thefnmark}}##1}% Later on in the class: \newcommand\@makefntext[1]{% \parindent 1em% \noindent ...


1

Here is another suggestion using \newkomafont to define a font style for this element. This also works if there is a table of contents. \documentclass{scrartcl} \newkomafont{frequentlyusedmacro}{\bfseries\itshape} \newcommand*\FrequentlyUsedMacro{{\protect\usekomafont{frequentlyusedmacro}Macro}} ...


3

I think the question is not clear enough. You are having a problem which you don't completely understand and you are asking for a particular solution that might not be what you really want. So here are a few shots in case one is exactly what you are looking for. The problem is that there's no sans serif bold italic in that particular font that comes by ...


0

I found a few solutions which I do not think are very clean. However, they might suit your needs: \documentclass{scrartcl} \newcommand\FrequentlyUsedMacro{\emph{\textbf{Macro}}} \newcommand{\startnoemph}{\let\emph\relax} \begin{document} \section{\startnoemph \FrequentlyUsedMacro{}} This works with \FrequentlyUsedMacro{}. \end{document} Or: ...



Top 50 recent answers are included