{parsing} is the process of analysing a string of symbols, either in natural or computer language.

learn more… | top users | synonyms

44
votes
4answers
3k views

Is there a BNF grammar of the TeX language?

I'm looking for a BNF grammar of the TeX language, does it exist?
21
votes
5answers
377 views

How to define a command that surronds an argument with parenthesis if it contains a comma?

I have a very simple command in which one of the arguments can contain commas, in which case the output may not be easily readable since the text in which it is used may contain other commas, making ...
18
votes
3answers
326 views

What are the effects of an empty group, {}?

In order to have a syntactic space after a no-argument command, one is taught to delimit the command token with an empty group ({}), like this: \somecommand{} more LaTeX material. However an empty ...
16
votes
5answers
455 views

Applying an operation only to capitals

I'd like to apply a function to capitals only so that: \emphcaps{YaWeH} Outputs like: \emph{Y}a\emph{W}e\emph{H} Preferably without using too many packages (I already use memoir). NOTES: I use ...
16
votes
4answers
2k views

Syntax of TeX/LaTeX

{} and [] do some kind of grouping, and comma seems to be special as well. Being a programmer I find it frustrating to use Latex on incantation-only basis. I would like to know how does it exactly ...
13
votes
4answers
841 views

Drawing Young tabloids

I would like LaTeX to produce output like the following (without the 2 a so called Young tabloid), ideally by writing \ytabloidshort{123,56} (using one character per cell, ideally allowing ...
13
votes
5answers
863 views

Parse comma-separated list of command names with spaces

Problem This question is related to How can I specify a long list of math operators? – but with a twist: I want to allow spaces in in the comma-separated list, like so: \newacronyms{acm, ams, cpu, ...
13
votes
5answers
1k views

How do I write a macro having comma-separated and variable number of arguments?

I want to write a macro in LaTeX2e that can pass \textcolor, which is embedded in another macro, the values of the colour model gray, rgb, or cmyk. The number of arguments specified implies the colour ...
13
votes
1answer
146 views

What is considered a token for non-standard input encodings?

When I use an input encoding to (La)TeX that allows me to directly input characters such as é and ä (such as by declaring \usepackage[utf8]{inputenc}), how is a token defined? Specifically, is it ...
12
votes
3answers
264 views

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

How could LaTeX replace the tokens <= by the command \leq efficiently? Example 1: I have this code: \[ 2x <= 4x - 2 \] And I want to get after the compilation this: Example 2: \[ ...
12
votes
5answers
384 views

Parsing hexadecimal numbers to binary and iterating over bits

I'm currently working on a software for an graphic display, so I recreated it in TikZ for documentation purposes: I currently use this to set individual pixels on the display: \setpixel{x}{y} ...
12
votes
2answers
798 views

Parsing files through LuaTeX

This question has two parts: How would one generally parse a file with LuaTeX, assuming the file only holds data that is delimited either by spaces, commas or semicolons. How would you parse the ...
11
votes
1answer
4k views

pgfplot: Datafile format for datetime field

I have a datafile (which I may manipulate to any format), it contains a date-time stamp currently in the form "year-month-day hour:min" and a single variable for each recorded time. When I attempt to ...
11
votes
1answer
103 views

Parsing commands with multiple optional arguments

Some LaTeX commands accept multiple optional arguments. Here are some examples: \makebox[<width>][<pos>]{<text>} \framebox[<width>][<pos>]{<text>} ...
10
votes
2answers
277 views

The different meanings of LaTeX's \stop command

we know that \stop will cause LaTeX to stop parsing and output what it has processed up to this command. But then I discovered another way to use it, as demonstrated in this minimum working ...
10
votes
1answer
82 views

Scan argument for parentheses

I'd like to define a macro which expands to (#1) if #1 does not contain any parentheses, but expands to \big(#1\big) if it does. I'd choose simplicity over generality: if a solution works in the most ...
10
votes
1answer
411 views

Extract the logically first slide in a Beamer overlay specification?

When writing Beamer slides for a talk, I find that I often want to have some text (usually math) visible on a group of slides and be alerted on only the first slide in the group. For example, I can ...
9
votes
5answers
295 views

Parse dotted string, extracting last part

I want a macro that will separate a string like "1.2.3" into two parts: the part until the last dot (call that the context) and the last number. This seems a pretty basic application of a helper ...
9
votes
3answers
310 views

Implementing car and cdr in TeX

I've been trying to implement a macro that reads and transforms its argument into a different form...but I'm having quite a bit of trouble finding or creating even the most basic parsing tools. Case ...
9
votes
2answers
643 views

\def taking next word as argument?

This question is a variant of my previous question requesting a macro that takes the rest of the line as argument. I would like to write a macro that would take the next word as argument, where word ...
8
votes
2answers
85 views

Parsing various types of page ranges with a single command

Having to treat a considerable amount of page ranges, I'd like to have a robust and simple command that would parse and print them correctly. The most simple case is e.g. 264,15-26 which ...
8
votes
2answers
2k views

What parsers for (La)TeX mathematics exist outside of the TeX engines?

Inspired by the author's motivation for asking Is there a BNF grammar of tex language. Are there any well done libraries that can parse some subset of TeX mathematics independently of the TeX engine? ...
8
votes
1answer
243 views

Replacing Leading Minus Signs in Environment

In this question concerning negative signs and the alignment of entries in matrix environments, Heiko Oberdiek gave a great answer in which he uses a user-defined command called \matminus instead of ...
8
votes
0answers
125 views

Parsing question: Do curly braces affect LaTeX compilation time?

I have an old and slow computer and long LaTeX files. When typing I prefer to use \frac 1{x} instead of \frac{1}{x} or x_i instead of x_{i}. Does the presence or omission of curly braces in these ...
7
votes
4answers
338 views

Read command with varying input arguments

Out of curiosity I'd like to define a LaTeX command that looks like: \newcommand{\trigger}{out1,out2,...,outn} with a rather strange function (at least, I couldn't find anything like this ...
7
votes
4answers
185 views

How to break a line after the n-th word?

Suppose i have a raw text defined as: \newcommand{\rawtext}{this is some raw text with many words in it} How to break this line after a given word or position? Of course, i only have access to ...
7
votes
2answers
412 views

Formatting crystallographic indices

I would like to make a command in LaTeX that can be used like this: \zoneaxis{1 2 -3} \zoneaxis{2 -1 -1 10} and would produce this: $[1\,2\,\overline{3}]$ $[2\,\overline{1}\,\overline{1}\,10]$ ...
7
votes
2answers
940 views

Iterate over space-separated list

I’ll briefly explain the background in case this can be solved simpler but I’d still be interested in an answer to the actual question, too. My chapter titles are very narrow and use a large font so ...
6
votes
4answers
521 views

Parse a string into tokens of numbers and not numbers

I have a string that I want to parse into to numbers and non-numbers. For my purposes: A Number can EITHER be any sequential string of digits OR sequential string of digits with a . followed by ...
6
votes
4answers
240 views

Simple pre-parser to separate TeX and comments?

I want to write a mathematical paper both with formulas and with program snippets, side by side. However I do not want the programs displayed or documented by TeX, just be able to extract them into a ...
6
votes
4answers
393 views

List parsing with special input/optional arguments

I’d like to parse a list where the elements can be given as either [<pre>]<text>[<post>], where <pre> and <post> are optional, or (<special text>). I found a ...
6
votes
3answers
141 views

String parsing macro fails within custom cite command of biblatex?

I am trying to use the same string parsing macro as in String parsing macro fails within a minipage environment?; but this time in context of biblatex - and I'm having similar problems, I guess. ...
6
votes
1answer
108 views

Parsing a \$ as part of an improved \getargs command

As the author of stringstrings, I am acutely aware of its slowness. For small tasks, that slowness can be annoying. For larger tasks, it can be prohibitive. Recently, in using data column as ...
6
votes
1answer
127 views

Is it possible to scan until the end of the current `\item`

I do a lot of itemize lists in beamer presentation which, in a later step, I want to format nicely, for instance, typeset everything up to the first colon in boldface and the remaining part scriptsize ...
6
votes
1answer
162 views

Arbitrary text parsing from a separate file

I'm still very new to the world of TeX, so please bear with me if this question is unclear or has been asked before. I'm starting to figure my way through TeX and the millions of plugins and ...
5
votes
2answers
182 views

Why various syntaxes for various commands?

I understand that the standard syntax of commands in TeX is \name[optional-1]…[optional-n]{argument-1}…{argument-n} The tabular environment, however, apparently takes its optional arguments after ...
5
votes
3answers
210 views

Cartesian product of two lists as parameters for a command

Friends, I used to suffer a lot when had to iterate through elements of a list, but thanks to egreg's suggestion, I've been successfully using the etoolbox package for that task, e.g.: ...
5
votes
2answers
145 views

Parsing leading hardspaces

This question is related to (but distinct from) this question: Parsing a \$ as part of an improved \getargs command, which I asked earlier. I am experiencing a residual space in a string result from ...
5
votes
3answers
524 views

How to extract parts of (La)TeX document?

I want to run queries against LaTeX documents like these: get list of all equations, even if one declares \def\be{\begin{equation}} and uses it; get list of all arguments of some command (e. g. ...
5
votes
1answer
726 views

Generate a parse tree for TeX

If I google for parse tree and TeX. All I'm getting are how to draw parse trees in TeX. I want to know if there are programs that can parse TeX, and output a parse tree that's easy to manipulate.
5
votes
2answers
105 views

Simplifying macro for the align* environment for two column equations

The align* environment provides for a two column layout of equations, similar to the eqnarray* environment. \begin{align*} [left side of the first column] &= [first line of the first ...
5
votes
2answers
51 views

Different Behaviors Digesting \csname x\endcsname and Digesting \x (expansion issue)

This question has been significantly EDITED, as I learned more of the problem. If I was good, I would be able to create macros with multiple optional arguments, but not only can't I, but in this ...
5
votes
4answers
1k views

LaTeX parser to perform operations on tags (commands) and its content?

Is there a LaTeX parser available that can be run from a (*nix) command line, and that allows operations on LaTeX tags/commands and its content? What I am trying to do is, for example: script-wise ...
5
votes
1answer
96 views

Is it possible to run a command stored as text in a variable?

I have some complicated expressions with loads of nested commands which are difficult to work with. To solve this I wrote a parser using pgfparser which creates the expressions for me. I can then copy ...
5
votes
1answer
64 views

Processing a particular line of text in a document

My question points actually to a particular problem, as opposed to the more general type of problem suggested in the title -- which would nevertheless be interesting to me to see answered: I'd like to ...
5
votes
1answer
486 views

How does 'filecontents' keep LaTeX parsing while temporarily stop writing output

We all know filecontents.sty can do \documentcalss{article} \usepackage{filecontents} \begin{document} Hello World \begin{filecontents}{dummy.txt} No one will read this if I don't use it ...
5
votes
1answer
165 views

How to skip an `\item` entirely, with no side-effects?

In Ryan Reich's great answer to my question on onlyitems, he had LaTeX ignore an \item by setting it into a box and then not using the box, effectively discarding it: ...SNIP... ...
4
votes
1answer
395 views

String parsing macro fails within a minipage environment? [closed]

I am trying to work with a string parsing macro, found in the answer of TeX capacity exceeded while parsing a date string - TeX - LaTeX. Basically, I have strings num01, num02... num09 - from these, ...
4
votes
2answers
103 views

Parsing rows (`\\`) and tab characters (`&`)

I have a use for parsing what would look like tabular input data, except that it isn't part of a tabular environment, but rather the argument to a macro. So I developed two macros, \readTABrow which ...
4
votes
1answer
132 views

Plain TeX macro to read a document in Pig Latin

Say I have a file eng.tex: \def\encounter (#1){Hello, #1!} \encounter (World) \bye I convert it to Pig Latin and save it as pig.tex: \efday\encounterway (#1){Ellohay, #1!} \encounterway (Orldway) ...