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

learn more… | top users | synonyms

11
votes
3answers
4k 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? ...
13
votes
3answers
233 views

Accessing TeX token or exporting filtered plain text

(updated according to gained information) In the context of keyword extraction from arbitrary (La)TeX documents and simple manipulations with them (automated annotation), I would like to be able to ...
7
votes
1answer
79 views

Macro overloading, catcode redefining… or how can I parse XML with TeX?

Given this code that barely parse XML and print it as SXML (s-exp XML, aka lisp-style XML, aka XML-with-parenthesis): \catcode`@=11 \let\@xp\expandafter \def\@makeletter#1#2\@nil{\catcode`#1 \ifx\...
5
votes
2answers
36 views

footnote inside a tested string

I would like to create a footnote within a command that tests the parent string (using xstring), such as: \documentclass{article} \usepackage{etex} \usepackage{xstring} \begin{document} \...
30
votes
6answers
847 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: \[ ...
2
votes
1answer
33 views

Parse macro arguments char by char and for loop through these chars

I have an idea. I want to loop through every character in string argument of macro. For example: \def\dowithchar#1{% % some actions with #1 } \def\mymacro#1{% % further pseudocode for (every ...
13
votes
3answers
2k views

Ways to parse JSON in LaTeX?

I'm writing my recipes (food) in a small textfile in JSON. Are there any ways to parse this in LaTeX? I know, that are lots of templates dealing with recipes, but I want to have my own style, which ...
17
votes
5answers
690 views

Basics of parsing

I'm trying to master the art of parsing text one character at a time. The following is what I've discovered so far. Is this as good as it gets? I would really prefer not to do all those \edefs as ...
2
votes
1answer
51 views

How to get paragraph contents

I have been using the following trick to obtain the contents of a paragraph. It works most of the time, but not on macros like \lipsum or \end{document} or \end{minipage} which expand the \par ...
1
vote
0answers
84 views

Problem with microtype's `\textls` and math mode [duplicate]

I have some issues with classicthesis' \spacedlowsmallcaps command that I could bring down to the following MWE: \documentclass{scrartcl} \usepackage{microtype} \newcommand{\spacedword}[1]{\textls[...
1
vote
0answers
46 views

Raw typesetting output [closed]

I would like to invoke tex from an external program (python) and receive the output as a sequence of (glyph id or unicode (whatever tex uses), x, y, width, height) to render it myself. Is there some ...
4
votes
3answers
566 views

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

In my country, instead of tan, we use tg (this is just one of them). I want to be able to type \tg{x} and possibly \tgx So that Latex recognizes them. I tried defining them like this: \...
3
votes
1answer
45 views

Creating a command that concatenates an input string token by token

Using (first of all) xparse I want to create a command like this: \DeclareDocumentCommand{\c}{ s > { \SplitList { ; } } r""} { % do something } It basically should just do the following: ...
3
votes
1answer
72 views

How to properly parse […]{…} with expl3?

What would be the more efficient way of parsing [...]{...} with expl3, that is to get the content inside the brackets in one variable and the content inside the braces in another one? This question ...
4
votes
2answers
93 views

Generalized File Name Parsing

In Parse filename and extract revision from name, the OP wanted to parse a file name of the format cv3.01 to extract the revision number 3.01. @egreg posted the following solution for a file name ...
7
votes
2answers
135 views

Parse filename and extract revision from name

My file is named 'cv3.01.tex'. I want to extract the '3.01' part and use it in the footer of the document, i.e. 'Rev 3.01'. I found Parsing file name into document, but it does not work for my ...
1
vote
1answer
50 views

Parse Argument by Character while Executing Embedded Macros

I am interesting in parsing a string of input character by character, and doing something to each character. In this MWE, I merely apply a \textbf to each successive character as an example, to ...
4
votes
1answer
90 views

Is there a parser of classic LaTeX/ConTeXt syntax?

Every time a question about parsing tex syntaxes come up, the first answer is: it's not possible and here is an (convuluted) example why. So I'm trying to narrow the scope of the question to what I ...
7
votes
4answers
679 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 ...
0
votes
1answer
89 views

new \input{file} Package, Command wrapper: microtype .tex with reserved symbols

I know enough LaTeX to produce great looking documents. LaTeX makes it more difficult to NOT do that. But I don't advanced LaTeX or TeX or plainTeX or "@" or other advanced, cryptic programming tricks,...
6
votes
3answers
122 views

Extract all arguments of a certain command from a document

I have a command \foo which takes two arguments and which I use about a hundred times throughout my document (but never within an argument of another instance of \foo). I now want to spellcheck every ...
64
votes
4answers
6k views

Is there a BNF grammar of the TeX language?

I'm looking for a BNF grammar of the TeX language, does it exist? EDIT For those of us who are not computer scientists, a BNF grammar is one kind of formal description of a CFG: Backus Naur Form. ...
3
votes
2answers
79 views

Formatting Strings in Dynamic Variables with xstring

I need to format a string resulting from a dynamic variable set in a separate program for a LaTeX generated report. In particular, if a variable has a negative value (starts with a minus sign), I ...
1
vote
1answer
65 views

Next word macro inside braces

I have defined a macro that highlights the next word using \def!##1 {\hkw{##1} }% where in this scope, ! is an active character. So it works fine to write. \emph{This is a !good example} but not ...
3
votes
1answer
109 views

List separated by semicolons, ending with a period

I am using a university-developed document class for my thesis. This class has the command \keywords which takes a list of \key commands and this is printed out as a keyword list after the abstract. ...
3
votes
1answer
165 views

Is there a formal grammar for *Equations* in TeX/LaTeX?

I've looked at this and this and understand there is no grammar of TeX as a whole. I am wondering if there is a grammar just for equations. They are relatively easy to identify in an amsmath file ...
4
votes
1answer
155 views

In LaTeX, what is the most efficient way to search for an optional token in given input?

My question is inspired by this comment by Joseph Wright. Let's say we have input strings with varying character combinations, such as: ...
6
votes
1answer
262 views

Parse a file with a regexp and return first match

I need to write a command that searches a file for a string that matches a certain regexp, and inserts that string. I know how to parse a string of text using a regex with \usepackage{l3regex} \...
2
votes
2answers
205 views

Translate sage input to latex without simplifying

In sage it doesn't seem possible to print latex code of an expression without simplifying it in some way. For example \sage(x/x) should translate to \frac{x}{x} instead of 1, see this question on ask....
6
votes
3answers
365 views

Parse argument with a number and an optional letter

How to define a macro which takes a string made by number and an optional letter and then branches on the basis on the letter? Since this is an extension of an existing package, it is preferable not ...
7
votes
2answers
235 views

Parse command argument separated by comma

I want to mix several language in my document, and the output language can be chosen according to corresponding variable I want to define this kind of command \mulan[en,fr,ru]{arg1}{arg2}{arg3} to ...
4
votes
4answers
132 views

Recursive String Parsing

I have been working on writing a recursive stream processor in latex that converts a shorthand version of a set of highly used commands into a much longer form. The code below represents what I had ...
4
votes
1answer
71 views

List Parsing the ascii space character

I have been using the list parsing functionality from etoolbox and I have a weird use case in which I want a space separated list. \usepackage{etoolbox} \DeclareListParser*{\symbolListParser}{<...
1
vote
1answer
140 views

Is there a BNF-grammar for simple constructs of the TeX language?

(Previously) Is there a TeX grammar that parses simple constructs like document, enumerate, section, subsection, etc.? I'm not interested in parsing complicated constructs requiring a more complex ...
9
votes
3answers
279 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 ...
11
votes
3answers
468 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 ...
18
votes
4answers
2k 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 ...
6
votes
0answers
387 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
142 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
123 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
101 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
115 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} \...
13
votes
1answer
274 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 ...
5
votes
1answer
595 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 ...
16
votes
2answers
1k 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 ...
4
votes
2answers
556 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 ...
6
votes
2answers
173 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
108 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? ...
5
votes
2answers
408 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 ...
1
vote
0answers
17 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 ...