Questions tagged [parsing]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
26 views

Parse standard balanced group within verbatim context

Say I want to write a custom parser which reads characters in a verbatim context, where the parser argument should be split into several kinds of tokens: Ordinary characters, i.e. all characters ...
2
votes
2answers
124 views

Automatically remove \ifthenelse

Let's assume that you have a single LaTeX source file that can compile two arts of documents: a main conference paper and its extended long version. Inside, you use \ifthenese to produce the two ...
0
votes
0answers
30 views

Parse all equations in eps file

When I draw figures with a vector graphic program I can export them as .eps files. I know it is possible to use psfrag to replace given text in the eps file with another text which is then parsed in ...
2
votes
1answer
54 views

Efficiency of xstring (2e) vs. xparse (l3) in simple parsing

I understand string processing can be done on either LaTeX2e using xstring and expl3 using xparse (originally based on the 2013 thread "Tokenizing and parsing") I will be running a relatively simple ...
4
votes
1answer
45 views

Nested maths mode - Latex parsing

I needed a tiny bullet and found this solution : $\vcenter{\hbox{\tiny$\bullet$}}$ Howover, I don't understand how latex interpret / parse this formula. \vcenter is math mode \hbox and \tiny are ...
10
votes
1answer
120 views

How do I define a new TeX register with arguments in LuaTeX?

Some time ago I tried to implement the \pdfadjustinterwordglue from pdfTeX in LuaTeX using a callback. Getting the callback to work is pretty simple, but there is another major problem in the way ...
1
vote
0answers
47 views

How to iterate over tags in a latex file?

I am working on a problem where I have been given a file and I have to find all the cells in all the tables in the latex document(Basically I have to make a border for all the cells. Currently, I am ...
0
votes
0answers
44 views

Split LaTeX paragraphs into new lines after each sentence - re-formatting tool for VCS

I think this question has relevance and overlap on both stack-overflow and TeX forums, but suspect the TeX community might be better suited, so have posted it here. My text/tex files need ...
1
vote
1answer
71 views

In what ways can one write a parser in plain TeX or packageless LaTeX?

I want to write my own document class as a literate program with as minimal of a dependency tree as possible as an exercise to test my ability. I've implemented a stable foreach loop by shredding an ...
0
votes
1answer
44 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
169 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
30 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
106 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
52 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
843 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
221 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
68 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
109 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
152 views

LaTeX Nesting \verb in \section

Why is \section{\verb|mySec|} invalid LaTeX code.
2
votes
1answer
79 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
382 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
161 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
104 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
404 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
657 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
161 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
407 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
3k 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
430 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,...
3
votes
1answer
1k 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
124 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
153 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,...
14
votes
2answers
661 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
180 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
154 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
246 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
115 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
248 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
716 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
186 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
68 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
360 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
72 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
143 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
112 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[...
7
votes
3answers
6k 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
63 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
108 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
204 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
307 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 ...