# Tag Info

36

TeX, as designed by Knuth, has various registers addressable with an eight bit number (that is, from 0 to 255). Registers are of type \count \dimen \skip \muskip \toks \insert \box Let's consider the \dimen registers, for the others the allocation mechanism is similar. Each register is addressable by its number, for instance \dimen34=42pt \kern\dimen34 ...

19

An individual macro may only have one definition, but a combination of macros can parse the input stream: \def\aprint#1at#2,#3{The text #1'' shall be printed at $#2 \abovewithdelims()0pt #3$} \def\bprint#1by#2,#3{The text #1'' shall be printed by #2 and #3 Doe} \def\print#1#2{\csname#2print\endcsname{#1}#2} \print{Testtext}at 2,3 ...

16

classic TeX has 256 registers (eg count and dimen registers as allocated by \newcounter and \newlength in LaTeX. For some years LaTeX formats have used the extended etex (or pdf(e)tex engines rather than classic TeX, so actually there are 32768 registers available. However for compatibility reasons (or stubbornness, or apathy, depending on your point of ...

12

Ah the \ifnum funky brace groups beloved of TeX\halign programmers:-)  is part of the syntax for a number in TeX. 125 is a decimal "7D is hex and } is the character code of the specified character (which is also 125 as it happens). So.... {\ifnum0=}\fi the inner \ifnum is testing if 0=125 which is false so when expanded this is ...

10

This code works backwards up the paragraph. First the entire paragraph is broken into lines and placed into a box (which is assumed to contain alternating items of an hbox with a line of text and a glue item of baselineskip glue. Then from the end of the list the box is removed (with \lastbox) and either put into a new box being constructed or flipped ...

10

In the first definition, the argument is delimited by a space and a \par token: \long\def\testA#1 {\begin{quote}#1\end{quote}} \long\def\testB#1 \par{\begin{quote}#1\end{quote}} \ifx\testA\testB\message{EQUAL}\else\message{DIFFERENT}\fi prints EQUAL The first end-of-line in \testA is converted to a space token; the second one is converted to a \par ...

9

The \vtop box will be \hsize wide, so it disappears beyond the left margin. Try with \hbox to0pt{\hss\vtop{\hsize=4cm def}\hss} and you'll see it appear in the left margin. Let's do \hbox to 0pt{\hss\vtop{def}\hss}\showlists and the log will show ### vertical mode entered at line 0 ### current page: \glue(\topskip) 3.05556 \hbox(6.94444+0.0)x0.0, ...

9

Run texdoc etex and you'll get the documentation of eTeX. Two of the nice new features are \dimexpr and \numexpr. Instead of 256 available counters, dimensions, etc. there are now 2^{15}. ε-TEX increases the number of TEX’s count, dimen, skip, muskip, box, and token registers from 256 to 32768. eTeX is the default engine for all programs except of ...

8

Describing the algorithm used by TeX for breaking a paragraph into lines would require a book chapter. You can find the details in the TeXbook or in TeX by Topic. Let me give a short description for the normal situation, without mentioning hanging indentation or \parshape. To begin with, a paragraph is read in its entirety into memory. Any “horizontal ...

7

Using tcolorbox. This is breakable across pages and all the benefits of tikz and tcolorbox like borders, background colour etc can be exploited. \documentclass{article} \usepackage{xcolor} \usepackage{kantlipsum} \usepackage[many]{tcolorbox} %% splitbox--- \tcbuselibrary{skins,breakable} \newtcolorbox{splitbox}[1][]{ colback=white, left=0.5ex, ...

7

A space following a digit always terminates the <number> and is absorbed so \foo=2 \otherMacro would assign 2 to \foo followed (with no space) by the expansion of \othermacro Any other non expandable non digit token terminates the <number> but is replaced so \foo=2\relax\otherMacro assigns 2 to \foo then the token stream has \relax and the ...

7

If you don't want to do the conversion, \documentclass{article} \usepackage{amsmath} \newcommand{\RN}[1]{% \textup{\uppercase\expandafter{\romannumeral#1}}% } \begin{document} $\RN{4}+\RN{12}=\RN{16}$ \end{document} If you also don't want to do the arithmetic \documentclass{article} \usepackage{amsmath} \usepackage{xparse} \ExplSyntaxOn ...

6

What do we know about \mathon and \mathoff? They are displayed by \showbox, \showlists and in other situations where the contents of a box or of a typeset list are written to the terminal or the log file. As can be read in paragraph "12. Displaying boxes", all these are implemented through the procedure show_node_list, which displays a node list (the data ...

6

\documentclass{article} \usepackage{etoolbox} \begin{document} \def\TrimBraces#1#2{\expandafter\zzz\expandafter#1\expandafter{\expandafter\zz#2\zz}} \def\zz#1\zz{#1} \def\zzz#1#2{\expandafter\def\expandafter#1\expandafter{#2}} \def\a{Test} \TrimBraces\x\a \show\x %-- should be ->Test % OK \def\b{{Test}} \TrimBraces\x\b \show\x %-- should be ->Test ...

6

My solution is only a little alternative to David's solution. The main point is the same: TeX removes outer braces from separated parameter if they exist: \def\aa#1\separator{...} \aa {text}\separator -- #1 is text \aa {text}b\separator -- #1 is {text}b And my solution: ...

6

It is a tex primitive behaviour not something defined in LaTeX. It is consistent with most other primitive math mode syntax, that it generates an error in text mode. \alpha for example.

6

\vsplit splits a vbox at a legal breakpoint in the vertical list in that box. The vertical list in \mybox only contains a single unbreakable item the hbox from the one line paragraph that contains your parbox in its first line. All latex box commands start with \leavevmode so they start a paragraph with the normal indent, center in a center environment etc. ...

5

Is this something similar to what you'd like to get? \documentclass{article} \usepackage{microtype} \usepackage{kantlipsum} \begin{document} \kant[1] \newbox\mylongbox \setbox\mylongbox=\vbox{ \hsize=0.7\textwidth \kant[2-4] } \noindent\parbox[t]{0.2\textwidth}{% Blah blah blah, blah blah blah blah blah blah blah, Blah blah blah blah, }% ...

5

The syntax is \ifx\a\b stuff \else other stuff \fi and no grouping is implied. By going \ifx\a\b{ stuff }\else{ other stuff }\fi You were keping both branches in local groups. Note also that you are missing lots of % from ends of lines if you do not want to introduce white space into the output.

5

Most asymmetric two column layouts are best handled by a list environment. This allows page breaking to occur naturally in the main flow without having to guess where to vsplit it. Although if there is a possibility of a page break happening in the first few rows you should need to work a bit harder to prevent that or the hanging parbox will overprint the ...

5

TeX processes its input using several processors: input processor -> token processor -> expand processor -> main processor A gastro-anatomical terminology is mentioned in the TeXbook for this but I never use this terminology. The Input processor reads lines from file, appends \endlinechar and (maybe) re-encodes the line and outputs each line as a buffer ...

5

I have a little bit different opinion about \bgroup versus \begingroup than the previous answer. First, I give a short explanation about TeX internals: The { and } (more exactly the tokens with catcode 1 and 2) have four different meanings in TeX: they are the syntactic part of macro definitions: \def\foo...{...} each sequence of tokens scanned as single ...

5

The calculations can be done by \pgfmathsetmacro: \pgfmathsetmacro\vx{\asx-\sqx} \pgfmathsetmacro\vy{\asy-\sqy} \pgfmathsetmacro\magv{sqrt(\vx*\vx + \vy*\vy)} \pgfmathsetmacro\propx{\sqx + \vx/\magv+\winsetshock} \pgfmathsetmacro\propy{\sqy + \vy/\magv+\winsetshock}

4

In tex.web, you'll find 3826: @ @<Display math node |p|@>= 3827: begin print_esc("math"); 3828: if subtype(p)=before then print("on") 3829: else print("off"); 3830: if width(p)<>0 then 3831: begin print(", surrounded "); print_scaled(width(p)); 3832: end; 3833: end making it part of the "procedure Display math node. \mathon and \mathoff is ...

4

I was inspired by Bruno's solution but I suggest to use only one full expandable pass. The main effect is reached by \expandafter\ifx\csname foo\endcsname\fi which expands to nothing but sets the \foo to \relax. This is only sole assignment done at expand processor level. All other assignments are done in main processor of TeX. ...

4

Here's my take; it is assumed that \@nil doesn't appear in the expansion of the second argument. \documentclass{article} \makeatletter \def\TrimBraces#1#2{\expandafter\TrimBraces@aux#2\@nil{#1}} \def\TrimBraces@aux#1\@nil#2{\def#2{#1}} \makeatother \def\a{Test} \TrimBraces\x\a \show\x %-- should be ->Test \def\b{{Test}} \TrimBraces\x\b \show\x %-- ...

4

Quoting from the TeXbook, page 79 (last single dangerous bend) Exception: No interline glue is inserted before or after a rule box. You can also inhibit interline glue by saying \nointerlineskip between boxes. In the case without the rule, the interline glue is added as usual: compute the sum s of the depth of the upper line and the height of the ...

3

%!TEX TS-program = pdftex \catcode@=11 \long\def\@firstoftwo#1#2{#1} \long\def\@secondoftwo#1#2{#2} \def\first#1{\@firstoftwo#1} \def\last#1{\@secondoftwo#1} \catcode@=12 \first{{+tokens1+}{--tokens2--}} \last{{+tokens1+}{--tokens2--}} \bye Of course, if you don't have (or want) anything to do with LaTeX. There's no need for \@firstoftwo while ...

2

Such active characters let to the original character work exactly the same as the original character, except in delimited arguments from macros defined prior to the category code change, and within \csname...\endcsname constructions. \def\delimited#1&{} \let\amp& \catcode&=\active \let&\amp {\delimited...&} % BOOM: & is not seen ...

2

Here's just a “semi-generalization” (with expl3) of the solution provided by egreg. I tried exactly that before asking this question (just touching catcodes of ^^M and using an auxiliar command, inspired by the definition of \obeylines) but, unfortunately for me, it didn't work (I need more training with catcodes and groups and where to change catcodes and ...

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