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

learn more… | top users | synonyms

11
votes
3answers
319 views

Parser for decimal numbers in (plain) TeX

I need help writing a parser for decimal numbers using only TeX and plain TeX. The set of accepted inputs is given by the regular expression: (+-)?(0-9)*(.,)?(0-9)+ The parser need not do anything ...
9
votes
3answers
136 views

How to parse multiple arguments in TeX macros

I have dates formatted {yyyy-mm-dd}. I would like display the time elapsed between the dates in the form Y years, M months. Given the format of the dates, it seems easier to use arithmetic than to ...
16
votes
4answers
399 views

Bash lstlistings treats “$#” as a comment

Background: In Bash, $# represents the number of arguments, and # starts a comment. Consider the following Bash script: # This is a comment while [[ $# -gt 0 ]]; do echo $1 shift done Note ...
3
votes
0answers
77 views

Automatic dropcaps for the first letter of a chapter

I'm in the process of writing a LaTeX style for thesis dissertations, and would like to automatically transform the first word of a chapter to dropcaps. This is trivial to do manually using the ...
1
vote
3answers
112 views

Parse csv-list, function with >1 parameters as callback

In my texts I have to deal with lists, whose items need to be formatted seperatly, i.e.: \funktion[3][]{T}--\funktion{S}--\funktion[3][7]{D}--\funktion{T} In \funktion which leads to \emphsubsup the ...
4
votes
2answers
73 views

Add content from an external file to the input tokens for parsing

I have a possibly very long sequence of tokens which is parsed by a macro. I would like to be able to read parts of this sequence from external files, if this is possible. I made up an MWE for this ...
2
votes
0answers
67 views

Generating LaTeX reports from XML *without* external scripts

First of all, I apologize if this is pretty similiar in nature to my previous question: Reading and (custom) formatting a CSV (not \csvautotabular) I thought it would be better to separate the two ...
0
votes
1answer
58 views

Automatic parsing/extraction of single-argument commands from input (for use in new environment)?

I'm not sure whether this is in principle possible, so let me try to explain; consider this MWE: \documentclass{article} \usepackage[showframe]{geometry} \usepackage{tikz} \usetikzlibrary{calc} ...
5
votes
1answer
199 views

Using tikz diagrams in beamer with minor differences between slides

I'd like to highlight different parts of a tikz diagram in beamer slides using something like the \only command. I was able to do this at the level of nodes, which is probably fine, but as I have some ...
14
votes
2answers
586 views

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

Pardon the naive beginner question. In a command like: \textcolor[HTML]{4C7045}{dark green text}, or \documentclass[12pt]{article}, or \begin{figure}[htb], why are some arguments surrounded by [] and ...
6
votes
2answers
138 views

Arguments to function not losing braces

This MWE is boiled down so much the usefulness of the code is lost. However, the code nevertheless still exhibits the problem I'm encountering. \documentclass{article} \usepackage{pgffor} ...
1
vote
0answers
64 views

ASCII characters used in plaintext representation of TeX [closed]

I'm writing a parser/transformer thingie that accepts valid LaTeX, and emits valid LaTeX. Is there a list of ASCII characters that are allowed in TeX math mode? Or is any character fair game? ...
4
votes
2answers
272 views

Parsing and programming in TikZ

Background: I'be been reading the PGF manual (keys section) and today the TeX Book just arrived in the mail and just started reading chapter 7 (How TeX reads what you type) -- feeling like Mickey ...
7
votes
3answers
159 views

Only get filename and extension of listing, not whole path

I am trying to add the file name as caption. I was able to do this setting caption=\lstname but this shows the full path. I am now trying to get the name of the file and extension to show only. I ...
1
vote
0answers
16 views

Using \filename@parse gives error [duplicate]

I am trying to use the \filename@parse like this: \filename@parse{\lstname} but I get this error: ! Undefined control sequence. l.22 \filename @parse{\lstname} ? Am I missing some ...
4
votes
0answers
74 views

PGF pretty number printing equivalent in LaTeX

For TikZ and pgfplots I use : \tikzset{/pgf/number format/.cd,use comma,1000 sep={\,}} And all numbers are typeset accordingly, with no other command. Is there a way to have the same convenience ...
1
vote
0answers
57 views

Is LaTeX a context-free grammar? [duplicate]

How can you tell if something is a CFG or not? I am wondering if you could create a math/LaTeX parser using a parsing expression grammar (PEG), or not. Is this possible, and how can you tell?
5
votes
1answer
113 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 ...
6
votes
4answers
289 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 ...
5
votes
2answers
152 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 ...
6
votes
2answers
66 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 ...
2
votes
1answer
154 views

Turn recipes (rezkonv, mealmaster) into LaTeX code

To better organize my recipes I would like to store them in a database instead of having plenty of books being scattered all around. There are many programs to realize this by offering a GUI to either ...
13
votes
1answer
221 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 ...
4
votes
2answers
107 views

Parsing file name into document

I have a group of tex files named according to the following convention: xxx_yyy_zzz.tex I would like to use the components (xxx, yyy, zzz) of the file name as inputs in the document, n particular ...
11
votes
1answer
161 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>} ...
4
votes
1answer
160 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) ...
2
votes
0answers
62 views

How to maintain data to be both implemented and documented (in a personal package)

I'm looking for the best strategy for maintaining, in a personal package, a (long) list of data that has to be defined in the implementation and to be documented in the documentation. Let me be more ...
21
votes
5answers
397 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 ...
5
votes
2answers
193 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 ...
4
votes
2answers
136 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 ...
5
votes
1answer
72 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 ...
13
votes
3answers
328 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: \[ ...
10
votes
1answer
86 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 ...
12
votes
5answers
460 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} ...
2
votes
1answer
135 views

How to check if token is a macro?

I am thinking about possibility to parse LaTeX document. What I really need is to track category codes of symbols. As I understand TeX expands all of macros in his mouth and tracks changes of category ...
6
votes
1answer
915 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 ...
8
votes
2answers
90 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 ...
2
votes
2answers
824 views

How to automatically insert values into latex code/template

I'm in the process of generating an automated report in pdf from latex. Each report is the same, but has different values/graphs. The graphs is no problem, but what is the best way to process a latex ...
5
votes
2answers
153 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 ...
7
votes
4answers
196 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 ...
6
votes
1answer
127 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 ...
1
vote
0answers
126 views

Help with verbatim-like environments [closed]

I am writing a script for LaTeX shallow parsing (assuming that there are no complicated definitions in the preamble). First of all I decided to check the document for in-line verbatims and comments, ...
19
votes
3answers
362 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 ...
8
votes
1answer
294 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 ...
4
votes
2answers
388 views

Shell script which parses .tex files for figures

I would like to pull all figures including captions out of multiple .tex files and write them into a single new .tex file. This means I have to parse for \begin{figure} . . . \end{figure} and ...
9
votes
5answers
329 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 ...
10
votes
2answers
334 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 ...
1
vote
1answer
222 views

Using \SplitArgument with r() arguments in xparse

I have been experimenting with using the xparse package for custom document macros with a Markdown-like syntax. For example, I used to write \cut{x}{P}{Q} to produce . With the help of xparse, I ...
6
votes
1answer
212 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 ...
3
votes
2answers
259 views

How to stop a block of code from being parsed?

I would like to pass some latex code to lua directly without it being parsed: \directlua{ PrintPrettyLatexCode("LATEX CODE GOES HERE!") } BUT latex tries to parse the "LATEX CODE GOES HERE!". I ...