Tag Info

Hot answers tagged

6

You should use \ifx and not \if, that just compares character codes and does full expansion. \documentclass{article} \usepackage{lipsum} \let\unactiveDollar=$ \catcode`\$=\active \def\executedollar{% \ifx\isDollar$% \let\next=\executeDDollar \else \let\next=\unactiveDollar \fi \next } \def\executeDDollar{% \ifmmode \let\next=\]% ...


6

I believe the easiest way, though fairly draconian, is to place \RequirePackage[l2tabu,orthodox]{nag} in your document class, or \usepackage[l2tabu,orthodox]{nag} in whatever auxiliary package you may be providing. This will teach your users many things to be avoided, including $$...$$.


6

This loop just uses expansion. In order to use #1 as the loop counter it is easiest to define it anew each time, if you didn't want access to the counter you could more easily use \myrepeat{5}{some code} Note i didn't use \repeat as that name is taken in the existing \loop syntax. \documentclass{article} \def\myrepeat#1{\ifnum#1=0 ...


6

There are a number of possible approaches to doing this without the complexity: I'll cover a couple using expl3. First, if you don't mind keeping things non-expandable then you could do something like \documentclass{article} \usepackage{expl3} \ExplSyntaxOn \cs_new_protected:Npn \For #1#2#3#4 { \int_step_inline:nnnn {#1} {#2} {#3 - 1} {#4} } ...


5

The syntax rules of TeX allow for certain primitives to have an “argument” delimited by \bgroup or \egroup. The main examples are \hbox, \vbox, \vtop, \vcenter, \halign and \noalign. This is the basis where, for instance, \halign LaTeX builds tabular on: with \begin{tabular}{<arg>} the argument is transformed into a suitable preamble for \halign ...


2

Based on this answer by egreg, together with the \new@nextchar macro from the amsmath package, I have an answer that seems to work, at least for this example: \documentclass{article} \usepackage{lipsum} \RequirePackage{amsmath} \makeatletter \def\unactiveDollar{$} \catcode`\$=\active \def\@DDollar${% \ifmmode% \let\next=\]% ...


1

Thanks to the inspiration from David's and Joseph's use of #1 as placeholder for the loop counter, I was able to improve the implementation that I've given in the question. I'll post it here mostly as a learning exercise for anyone who happens to have a similar use case. This version only expands the loop counter and leaves all other tokens alone, removing ...


1

Here, I reset the counter to 0 before the final \onecopy and redefine \insertbox to step the counter with its output. \documentclass{article} \usepackage[box]{automultiplechoice} \usepackage{listings} % a simple wrapper to create boxes automatically \makeatletter \newcounter{myboxcounter} \newenvironment{mybox}{% \stepcounter{myboxcounter}% ...


1

I'm afraid you have to name the boxes, so that they can be retrieved in the right order. You can use the question ID as a name for the boxes: \documentclass{article} \usepackage[box]{automultiplechoice} \usepackage{listings} % a simple wrapper to create boxes automatically \makeatletter \newenvironment{mybox}[1]{% \expandafter\newsavebox\csname ...



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