# Tag Info

13

Assuming "character" means "a single character token in input" (so just ASCII with pdftex but Unicode input with xetex or luatex) then \documentclass{article} \usepackage{xcolor} \begin{document} \makeatletter \def\ColorNthChar#1#2{\xColorNthChar{#1}#2\@empty} \def\xColorNthChar#1#2{\ifnum\ifx\@empty#21\else#1\fi=1 \textcolor{red}{#2}\expandafter\@...

13

A simple implementation in expl3: \documentclass{article} \usepackage{xparse,xcolor} \ExplSyntaxOn \NewDocumentCommand{\colornth}{O{red}mm} {% #1 = color to use, #2 = position, #3 = word % deliver all characters before the chosen position \tl_range:nnn { #3 } { 1 } { #2 - 1 } % deliver the character in the chosen position with the desired color \...

12

Your reasoning is correct except for what the #{ parameter does. When TeX sees a # in the <parameter text> of a macro (as in \def\macro<parameter text>{<replacement text>}), the following token can be either a digit in the range 1–9, or a {. When the parameter is "the dreaded weird #{ parameter", then TeX behaves as if the delimiter ...

10

\documentclass{article} \usepackage{xcolor,xparse} \begin{document} \ExplSyntaxOn \NewDocumentCommand\ColorNthChar {mm} { \int_zero:N\l_tmpa_int \tl_map_inline:nn { #2 } { \int_incr:N\l_tmpa_int \int_compare:nNnTF {\l_tmpa_int}={#1} { \textcolor{red}{##1} } { ##1 } } } \ExplSyntaxOff % example ...

8

I've already dealt with the problem in my book on LaTeX programming. My example is slightly different, but it's easier to copy. ;-) Suppose we have \newcommand{\xyz}[2]{ab#1cd#2ef} This becomes \@star@or@long\new@command[2]{ab#1cd#2ef} As there is no * after \new@command, this does \let\l@ngrel@x=\long and \@star@or@long disappears. Now \new@command is ...

7

Something like this? \documentclass{article} \usepackage[T1]{fontenc} % for "\dh" macro \usepackage{amsmath} % for "\textrm" macro \newcommand{\crpartial}{\textup{\rmfamily\dh}} \begin{document} $dS \ge \frac{\crpartial q}{T}$ \end{document}

7

Here's a LuaLaTeX-based solution. Its three main working assumptions are (A) there are two levels of enumerated lists, (B) the strings \i and \ii occur at the start of a line, while possibly being preceded by whitespace, and (C) any lines with \par instructions are not preceded by all-blank lines. The third assumption is not (at least not explicitly) in the ...

7

TikZ has the parser module for that purpose. It allows you to parse a string of characters and do something with them. \documentclass[12pt]{article} \usepackage{tikz} \usepgfmodule{parser} \newcounter{pft} \pgfparserdef{ASCIIswitch}{initial}{the letter X}% {\stepcounter{pft}% \fill (0.18*\number\value{pft},0) circle [radius=0.08];}% \pgfparserdef{...

6

You can use expl3: no need for fancy indexing, which is provided out of the box with “indexed maps”. \documentclass[12pt]{article} \usepackage{tikz} \usepackage{xparse} \newcommand{\makedot}[2]{% \fill (0.18*#1,-0.18*#2) circle (0.08); } \ExplSyntaxOn \NewDocumentCommand{\ASCIIfont}{O{}m} { \begin{tikzpicture}[#1] \jlettvin_asciifont:n { #2 } \...

5

Here's a LuaLaTeX-based solution. It provides a Lua function that does the actual work and a LaTeX utility macro, called \ColorRangeChar, which passes its three arguments to the Lua function. The three arguments are (a) and (b) integers that indicate the positions of the first and last characters to be colored and (c) the word itself. This solution ...

5

Give \\ before \cmidrule \documentclass{book} \usepackage{cite} \usepackage{amsmath,amssymb,amsfonts} \usepackage{algorithmic} \usepackage{graphicx} \usepackage{textcomp} \usepackage{tabularx,booktabs,ragged2e,bm,newtxmath} % new packages \usepackage{pgfplots}\pgfplotsset{compat=1.14} \newcolumntype{Y}{>{\centering\arraybackslash}X} \usepackage{xcolor} %%...

5

Here are two ways to fix your code (quite different from the one given by Schrödinger's cat). Probably, your most important “mistake” is that you needed to expand the \row macro before feeding the result to \dowithchar, in the second picture. Also, I don't see the purpose of your \myspace macro, so I removed it. The second problem is that you needed \if ...

4

As Andrew said, expl3 has great high-level tools for many things, including list processing. But expl3 or not, the most important thing is to understand what you are doing, and post a minimal working example when you are stuck (your code doesn't have \end{document}). So, I'll focus on your “second approach.” You initialize the result with a first item which ...

4

For the sake of having fun you can implement your own \romannumeral0-expansion-based tail-recursive-loop-macro for interspersing the tokens that form the expansion of \row with commas. (If you do this, a bit of expansion-control is needed to get all tokens into correct order, but that might be a nice and relaxing exercise.) Then you can use the comma-list ...

4


4

\documentclass{article} \usepackage{xcolor} \newcounter{pft} \begin{document} \makeatletter \def\pft#1-#2;{\edef\lower@pft{\the\numexpr#1-1}\edef\upper@pft{\the\numexpr#2+1}}% \def\ColorRgChar#1#2{\pft#1;% \setcounter{pft}{0}% \@tfor\next:=#2\do{\stepcounter{pft}% \ifnum\value{pft}>\lower@pft \ifnum\value{pft}<\upper@pft \textcolor{red}{\next}% \...

4

If you're happy with U+00F0 LATIN SMALL LETTER ETH, that is, ð, then you can define it as a math symbol. I used italic, that seems more appropriate. \documentclass{article} \usepackage{amsmath} \DeclareSymbolFont{toneitalic}{T1}{\familydefault}{m}{it} \DeclareMathSymbol{\cpartial}{\mathord}{toneitalic}{"F0} \begin{document} \begin{equation*} dS\ge\frac{\...

3

The command \path from hyperref is handy here: \newcommand{\mytopic}[1]{% \item {\path{#1}} \\ \includegraphics[scale=1.1]{#1} \\[2ex] } \begin{enumerate} \mytopic{DSC_0942} \end{enumerate} \path allows underscores and other characters used for file paths -- exactly what you need.

3

You might do as follows, but I'm not recommending it. \documentclass[12pt]{article} \usepackage[ngerman]{babel} \usepackage{etoolbox} \makeatletter \robustify\- \let\latex@hyphen\- \renewrobustcmd{\-}{% \ifmmode (my cmd)% \else \expandafter\latex@hyphen \fi } \makeatother \begin{document} a\-b $a\-b$ \end{document}

3

The bulk of the code is managing the input. The second argument can be a single number, meaning just one character to color; -, meaning color everything; m-, meaning color from the m-th character to the end; -n, meaning color from the start up to the n-th character; m-n, meaning color from the m-th up to the n-th character. \documentclass{article} \...

3

Here is an extension of egreg's first code in this answer to support ranges of the form min-max, where min means “start” if not given, and max means “end” if not provided. My code uses l3regex to parse the range expression. \documentclass{article} \usepackage{xcolor} \usepackage{xparse} \ExplSyntaxOn \msg_new:nnn { salim } { invalid-range-expression } { ...

3

I think that you want to use the easylist package. It does not quite give you all of the features that you want but it is pretty close. For example, the code: \documentclass{article} \usepackage[sharp]{easylist}% sharp => # is used for \item \begin{document} Some text here \begin{easylist}[articletoc] # first item # second item more text ...

3

This is essentially in expl3 out of the box. The idea is to map the original list; if an item is not in the remove list, add it to a temporary list and, at the end, reset the original list to the temporary one. I added just some syntactic sugar to name lists, which allows to have many of them without defining new macros. \documentclass{article} \usepackage{...

2

A different approach with listofitems. In essence, I use the remove-list as the list separators. Thus, they don't show up in a digested list regurgitation, because they were removed as list separators (along with the excess commas). \documentclass{article} \usepackage{listofitems} \newcommand\subtractlists[2]{% \expandafter\setsepchar\expandafter{\...

2

Some preliminary remarks about how (La)TeX works: The command \the⟨counter⟩ may not only deliver digit-tokens in range 0..9 which denote the value of the counter. It may also deliver (non-expandable) tokens for pretty-printing the value which disturb calculation and \setcounter-assignments. Instead use \number\value{⟨counter⟩}. ...

2

To solve your first problem, I would define two commands - one for important terms, which should be used when you want the index entry even in the Epub file, the second for all instances you want in the PDF version. The second issue can be solved using multiple TeX files - separate file for the print on demand, another for other uses. Document text can be ...

2

A little bit late to the game, but here's a LuaLaTeX-based solution. The solution is set up to work with non-ASCII-encoded characters such as öäüßÖÄÜ. % !TEX TS-program = lualatex \documentclass{article} \usepackage{xcolor} %% set up the Lua function that does the actual work: \directlua{ function color_nth_char ( n , s ) local t t = unicode.utf8.sub(...

2

You can, but isn't it simpler to use \newcommand? \begin{filecontents*}{compensation.tex} \begin{tikzpicture}[auto] %placing the nodes \node[signal] (input) {}; \node[ block, right = of input ] (controller) {linearer Regler}; \node[ block, path picture = { \draw[...

2

The tokcycle package has reasonably extensive ability to glean the characteristics of a token, as shown in this MWE. In lines 1.-7., I show some of these abilities. In lines 8a. and 8b., I propose how to find a macro, which I define here as an expandable control sequence. \documentclass{article} \usepackage{tokcycle} \newcommand\characteristics{% \...

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