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
3
votes
2answers
50 views

Convert \input to number

I'm reading several txt-files from disk and I want to do some simple calculations on them and be able to print them on the page. Basically I have: \newcommand\getinput[2]{ \immediate\write18{do-...
6
votes
4answers
348 views

What LaTeX macros cannot accept a group as an argument?

I am working on a LaTeX pretty printer that parses a LaTeX document and then re-renders the source. (I know that this is not possible in all cases, but it should be possible a lot of the time.) In ...
0
votes
0answers
22 views

Automatically elaborate an external table's data

I have to create a serie of sheets with LaTeX using informations from a LibreOffice table (but I can convert it in other formats if needed). The problem is, the table is some hundreds rows long, so it ...
6
votes
1answer
128 views

Why does LaTeX parse square brackets differently than curly braces?

In this comment (copied below without effort to preserve formatting): It may be worth pointing out why this happens. The [ and ] bracketing of optional arguments in LaTeX isn't as robust as the { .....
2
votes
1answer
87 views

How to escape “and” as list delimiter in bibtex/biblatex?

In my BibLaTeX manual, it says: Literal lists are parsed and split up into the individual items at the and delimiter but not dissected further. Literal lists may be truncated in the bib file with ...
3
votes
3answers
103 views

Parse sentence and split into parts

I would like to generate titles for my documents that look like this: \documentclass{article} \usepackage{tikz} \begin{document} \noindent \colorbox{red}{\expandafter\MakeUppercase\expandafter{\Huge ...
3
votes
1answer
147 views

In LaTeX3, what is the best data type for storing, parsing and outputting free user input?

I'm working on a mini-parser that takes free user input and interprets certain inputs as commands. For example, the parser interprets + as \oplus or [ as "start a pre-configured array with the bracket ...
0
votes
1answer
40 views

Combining texmate header and xskak notation

I tried to alter the PGN2LaTeX3 in that manner that it should create headers in my book, however I failed to do it. for example, some pgn2latex_out.tex result: \newgame \resetPgnTags \def\Site{} \...
0
votes
0answers
29 views

Output position in sourcefile of a macro expansion

Suppose I have a custom macro defined with \newcommand (no fancy parsing going on). For simplicity assume \newcommand{\mymacro}[1]{#1} Is there a way to redefine the macro so that, every time the ...
2
votes
1answer
33 views

Build a shortcut for string to be used as an argument later

I need to pass the result of a macro as a string to another macro (I'm using xparse). Here is a minimum working example: \documentclass{minimal} \usepackage{xparse} \NewDocumentCommand{\...
26
votes
3answers
1k views

Unbalanced dollar signs

I'm curious: why do the following two examples behave differently? Example 1: (Works, displays xyz in displaymath mode.) \newcommand\weird{$$xyz$} \weird$ Example 2: (Error, missing $ inserted.) \...
2
votes
1answer
39 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
151 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
69 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
67 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
85 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
166 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
52 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
63 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
84 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
54 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
178 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
32 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
143 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 ...
2
votes
1answer
122 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 ...
6
votes
2answers
2k 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
315 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
74 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
160 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
238 views

LaTeX Nesting \verb in \section

Why is \section{\verb|mySec|} invalid LaTeX code.
2
votes
1answer
83 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
424 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
229 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
119 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
428 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
700 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
166 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
435 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, ...
11
votes
1answer
4k 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
594 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
128 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
200 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
685 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
218 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
166 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
322 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
131 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
310 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
870 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 ...