Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [parsing]

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

0
votes
1answer
38 views

How much negative space needed? To recognizably remove a space by letting something be added? For macros whose argument is another macro?

Suppose that one has brea + (notice the space at the end). brea + is not printed yet. A macro \m{brea +} will replace + with \added ... how then does one define added, imagine it prints a d but only ...
4
votes
3answers
155 views

Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset

What is a good way to write a definition of the type \fun below \fun{abc1 EDF1 xyz1 efg jkl abc2 EDF2 xyz2 efg jkl abc3 EDF3 xyz3 efg jkl abc4 EDF2 xyz4 ...} where the number of arguments is not ...
1
vote
0answers
27 views

Latex3 replacement for \afterassigment in parsing code to grab integer

When parsing expressions, one way that I like to grab an integer delimited on the end by any nonexpandable token that is not a digit is using a count register and \afterassignment. So the code looks ...
3
votes
3answers
79 views

Check whether String represents valid number for PGF

I am searching for a reliable way to determine whether a String can be fed into \pgfmathprintnumber. I used to use the \IfDecimal from the xstring package which works fine for things like 3.14 and ...
1
vote
1answer
37 views

Iterating over characters of a string during a for each loop in a Tikz picture

I am trying to make a command that renders a Tikz picture in which there is a square surrounded by a number of smaller squares on the boundary. The first parameter defines the size of the picture, the ...
5
votes
2answers
432 views

Parser for pure LaTeX

Is it possible to create a parser for pure LaTeX (no plain TeX, no TeX primitive) without using any TeX engine that supports total LaTeX? I know about an iOS app to create and typeset LaTeX and I don'...
3
votes
0answers
196 views

Is there a BNF grammar of the LaTeX format?

I know it seems like there is no BNF for TeX language. But I am interested in BNF, PEG or any other kind of formal grammar for the LaTeX format. Is it possible to create such a grammar for pure LaTeX ...
1
vote
1answer
61 views

Stripping leading characters from command parameter

I have a command (AlertShort) with one input parameter that both prints text and generates an index. For standard text this works fine but, in some cases, the input parameter contains a symbol which ...
1
vote
1answer
95 views

LaTeX Grammar and Nesting Rule

Is there any grammar and rule describing the allowed nestings and combinations and the allowed format of the arguments in LaTeX? E.g. \section{\verb|mySec|} \section{\begin{huge}mySec\end{huge}} \...
2
votes
1answer
101 views

LaTeX Nesting \verb in \section

Why is \section{\verb|mySec|} invalid LaTeX code.
2
votes
1answer
74 views

Latex reformat text structure

Say I have a file of abbreivations.txt &Estimated &Time of &Arrival &North, &East, &West, &South &Special &Weapons &And &Tactics &W&ireless &F&...
8
votes
4answers
355 views

Runaway argument? with \newcommand[2]

I have a date (in the format YYYY.MM.DD) and a time (format HH:MM). From these, I want to compute a kind of TimeStamp/Total of minutes. \documentclass{article} \makeatletter % Timestamp \...
1
vote
1answer
87 views

Runaway argument? with \def

I have a time value in the format HH:MM (i.e 03:00). I need to compute the TotalMinutes of this time (expected result 180). My current code is \documentclass{article} \makeatletter \newcommand{\...
1
vote
1answer
92 views

Parsing function arguments and brackets

I've been trying to get a macro to work without any kind of success. I want a function \graf{} to take a list of arguments separated by a semicolon. These arguments need to be passed to the function \...
8
votes
4answers
377 views

Check for group as argument (expandable)

I want to check whether an argument of a command is fully contained in a pair of curly braces without using any extra packages. For this I define two macros containing { and } with catcode 12, ...
11
votes
6answers
618 views

How to go about creating custom parser in Latex

Say I wanted to write a macro like this: \makelinesegment{1:1-1:2-2:2} And have it become something like: \draw (1,1) -- (1,2) -- (2,2); The question is, how to go about parsing that 1:1-1:2-2:2 ...
5
votes
1answer
160 views

Control symbol formed by escape character followed by return

Does the control symbol obtained by following the escape character by return (\<return>, catcode 0 then catcode 5) behave like the control space character (\<space>, catcode 0 then catcode ...
10
votes
2answers
398 views

When is \catcode executed?

According to the TeXbook, characters in a file are first converted to tokens with catcodes ("mouth") and then any nonexpandable commands are executed ("stomach"). \catcode is a nonexpandable command, ...
10
votes
1answer
2k views

How does “\char`” work?

In LaTeX, you can use \char` followed by a symbol to get that symbol. For example \char`b or \char`\b would just yield the letter b. Which symbols/letters does that work for? Two ...
7
votes
1answer
331 views

How to increase minimum space between words in XeLaTex output?

Update: The problem seems to be that the spacing between some words is too small, and the ATS thinks it's one word. So, the ideal solution would be to set a minimum spacing across the entire document,...
4
votes
1answer
714 views

Load fields from JSON file using LuaLatex

I want to load a lot of numbers in my document from a single JSON file that is returned from a simulation. To do that I so far followed this stackexchange answer but for multiple values I would have ...
0
votes
0answers
115 views

Compute image ratio based on the largest picture available in the document

Following this question I asked a few years ago, I'm looking for a way to find the width of the largest picture (in width) in my document. Typically, this requires a for loop and some TeX programming....
3
votes
1answer
120 views

Automated Code Listing Line Numbers

I want to automate source code examples in my documentation. Listing comes very close to doing this as it allows specification of start and ending line numbers: \lstinputlisting[firstline=300,...
15
votes
2answers
648 views

What are tokens used for?

When reading TeX for the impatient, we learn that: The "eyes" of TeX convert the input file into a sequence of characters; Then the "mouth" of TeX converts the character sequence into tokens; Then ...
2
votes
1answer
134 views

multi-striped nodes

I'm trying to create a pgf key that will achieve multicolored nodes with left-to-right stripes using the method outlined here. However, I would like to provide a more convenient usage for this, ...
1
vote
1answer
142 views

Command with argument and several results inside command (inside command…)

I want to reuse a command that performs the same type of action (a specific parsing of the incoming expression) inside the other command, which should form the contents of the document and can also ...
4
votes
3answers
179 views

How do I extraxt a value from a “key1=value1,key2=value2” list?

I have a comma-separated list of key=value strings. I want to extract the value based on the key. Something a bit like \LookUpValue{c}{a=foo,b=bar,c=baz,d=zyyzx}{error:notfound} The intention is ...
3
votes
2answers
103 views

What causes this runaway argument when attempting to parse \jobname?

I’m attempting to parse the jobname of my (Xe)LaTeX document to set a true/false flag for later use. I came across this solution which seemed promising and which I implemented (see the following MWE). ...
5
votes
3answers
218 views

Split input at hyphen or space

I need to treat input differently, depending on whether it contains a space or a hyphen. That is, the following \foo{foobar} \foo{foo bar baz} \foo{foo bar-baz} \foo{foo-bar baz} \foo{foo-bar-baz} ...
6
votes
1answer
602 views

Extract filename from path

For labelling purposes I want to print the filename with extension given a full file path (in \tt font) Based on Egreg's answer in Only get filename and extension of listing, not whole path I cooked ...
7
votes
1answer
173 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\...
4
votes
2answers
63 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} \...
12
votes
3answers
345 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 ...
3
votes
1answer
62 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 ...
1
vote
2answers
128 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
106 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[...
6
votes
3answers
5k 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: \...
2
votes
1answer
61 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: convert ...
2
votes
1answer
102 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 ...
3
votes
3answers
196 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
288 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
118 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 ...
3
votes
1answer
261 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 ...
5
votes
3answers
149 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 ...
3
votes
2answers
211 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 ...
2
votes
1answer
334 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. ...
1
vote
1answer
70 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 \...
-1
votes
1answer
128 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,...
5
votes
2answers
713 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 ...
3
votes
1answer
177 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: ...