# Tag Info

Accepted

### Unbalanced dollar signs

First example: \newcommand\weird{$$xyz} \weird \weird is expanded to$$xyz$and processed; The first$ is identified and TeX searches for a following $since there's a difference in how$...$and$...
• 569k

### Ways to parse JSON in LaTeX?

Although the question is about parsing JSON in LaTeX, since the OP wants to "have my own style, which can be change very fast", I'll give a ConTeXt solution for its simplicity. ConTeXt already comes ...
• 61.1k

### What are tokens used for?

There are some technical differences but mostly it's just the "idiosyncratic" terminology used by D. Knuth, almost all systems are parsed in stages that separate lexical analysis (eg distinguishing a ...
• 673k
Accepted

### Defining \tg so it behaves exactly like \sin and \cos?

All you need to do is write \DeclareMathOperator{\tg}{tg}; this defines the command \tg to use the normal math font. Then, you can define \tgx to just be \tg x: \documentclass{article} \usepackage{...
• 6,906

### Ways to parse JSON in LaTeX?

Try this: \documentclass{scrbook} \usepackage{luacode} \begin{filecontents*}{test.json} { "recipe": { "title":"First recipe", "source":"My first cookbook", "carbs":"1 oz", "fat":"1 ...

### Ways to parse JSON in LaTeX?

As always, I missed David's comment, so my idea is not 100% original. :) As David said in the chatroom, he subliminally gave me a hint, which proves his powers are beyond comprehension, and that ducks ...
• 43.2k
Accepted

### What is the difference between square brackets and curly brackets in a command invocation?

In TeX (and LaTeX and ConTeXt) braces ({}) are used as grouping characters. In LaTeX, brackets ([]) are conventionally used for optional arguments, whereas braces are used for mandatory arguments. ...
• 13.1k

### Dynamically count and return number of words in a section

Here is a pure LaTeX solution to the problem, using my tokcycle package (I even offer a pure TeX solution at the end!!). You will need the new version from 2021-03-10, because I define my environment ...
Accepted

### How does "\char" work?

It is a misunderstanding to attach the left quote to the \char command as you do by writing \char. \char expects as argument a number. With the left quote you are converting the next character or ...
• 296k
Accepted

### Parsing question: Do curly braces affect LaTeX compilation time?

The version without the braces is processed a tiny bit faster than the version with braces. Typesetting one million times $\frac12$ required 8.69 seconds, while a million $\frac{1}{2}$ took 8.81 ...
• 1.0m

### Accessing TeX token or exporting filtered plain text

In ConTeXt, one option is to export your document as XML. You can then manipulate the resulting XML document using standard XML tools in your favourite programming language. As an example, consider ...
• 61.1k
Accepted

### Parser for pure LaTeX

If you write a parser you can define the subset of latex that you support. (There isn't really a useful definition of "Pure LaTeX with no primitives".) For instance MathJax has a parser for a subset ...
• 673k

### Unbalanced dollar signs

As explained in chapter 24 of the TeXbook, a (category code 3) $cannot be in vertical mode: if it is found when TeX is in vertical mode, horizontal mode is started and$ is reexamined. Chapter 25 ...
• 1.0m

### How could LaTeX replace the tokens <= by the command \leq?

This is interesting problem which can be solved by more compact macros than in accepted answer: \long\def\isnextchar#1#2#3{\begingroup\toks0={\endgroup#2}\toks1={\endgroup#3}% \let\tmp=#1\...
• 54.1k
Accepted

### When is \catcode executed?

TeX absorbs one record (typically a line) at a time, but doesn’t immediately tokenize it. It rather normalizes it changing the EOL character(s), if the operating system uses it (them), with the ...
• 1.0m
Accepted

### Basics of parsing

The accepted TeX solution here includes several problems. One of them is that whole argument is read at each step, no only one token. The second is that the recursive loop in the accepted code ...
• 54.1k

### How could LaTeX replace the tokens <= by the command \leq?

Here's a LuaLaTeX-based solution. It defines a Lua function, named do_subs, that performs substitutions on all the following two-letter and three-letter character combinations: <== <=> ==>...
• 443k

### Parser for decimal numbers in (plain) TeX

EDITED to seamlessly handle dots and/or commas as the decimal separator. REEDITED to provide error checking. The error handler works by pre-processing the string and removing "numerically valid" ...

### How to go about creating custom parser in Latex

Version 1: My answer is using mostly TeX primitives. I know there are other ways to do it, especially using expl3, but I'm not there yet, so... I defined the main macro \makelinesegment that will ...
Accepted

### Why does LaTeX parse square brackets differently than curly braces?

TeX recognizes only two grouping characters. These are the characters assigned the catcodes 1 (begin group) and 2 (end group). By default they are { and } respectively. The [ and ] characters are ...
• 203k
Accepted

### Automatic text highlighting based on a dictionary

Define dictionary words separated by || using the \setsepchar macro. Then, after \begin{document}, issue \def\currentword{}\tokencyclexpress and before \end{document}, issue \endtokencyclexpress. ...
Accepted

### Bash lstlistings treats "\$#" as a comment

Whoever wrote the listings language for bash probably didn't anticipate this case. Actually, the listings package is a far cry from a proper lexical analyser and doesn't offer a clean way of doing ...
• 56.7k
Accepted

### Parse argument with a number and an optional letter

\documentclass{article} \makeatletter \def\myparse#1{\afterassignment\xmyparse\@tempcnta#1\relax} \def\xmyparse#1\relax{\csname myparsexx#1\endcsname} \def\myparsexxb{Beginning of \the\@tempcnta} \...
• 673k

### Basics of parsing

Scanning one token at a time requires at least distinguishing whether the scanned token is a space or a left brace. This is because you can't remove the scanned token with a one parameter macro in ...
• 1.0m
Accepted

### What are tokens used for?

Let me ignore the eyes–mouth–stomach (and…) terminology mentioned in the question, which is truly unique's to Knuth's description of TeX, and focus specifically on the tokens that the question asks ...
• 42.8k
Accepted

### LaTeX3 - Parsing an argument to apply specific macros

You can parse via regular expressions. \documentclass{article} \ExplSyntaxOn \NewDocumentCommand{\parseanduse}{m} { \projetmbc_parseanduse:n { #1 } } \NewDocumentCommand{\macroO}{m} { \...
• 1.0m

### How could LaTeX replace the tokens <= by the command \leq?

ConTeXt has this funny asciimath module, which has unfortunately completely different rules (which are highly inconsistent), but it still fits the general task though. Probably there is something ...
• 106k

### Parser for decimal numbers in (plain) TeX

this version is not expandable but it doesn't need any terminator, it just gobbles up as far as the end of the number. It is restricted to integers that fit in a tex count register. \newcount\ca \...
• 673k