Questions tagged [parsing]
{parsing} is the process of analysing a string of symbols, either in natural or computer language.
186
questions
1
vote
0
answers
52
views
Detect \end of an environment
I'm trying to create a macro that grabs everything till the end of the current environment and parses it. At first, I just want to put ! right after my macro and another one ! before the end of ...
1
vote
1
answer
46
views
How to parse an itemized list the way moodle.sty does
A simple moodle.sty database contains code like that:
\begin{multi}{Name of the question}
Text of the question
\item first answer
\item secon answer
\item* the starred is the ...
2
votes
2
answers
60
views
How to gobble a character, if present
I would like to do the folloging:
Given a (complicated) string/macro \String, if it starts with * I just remove it, otherwise I do nothing.
So far I tryed
\def\gobbleast *{}%
then \gobbleast \String ...
0
votes
0
answers
34
views
Is there a way to extract math from a pdf in LaTeX format using SESHAT?
So I've been tasked with using SESHAT to extract the math problems from a large pdf into latex format, but seshat requires an InkML or SCGink file type as it's input. Is there a way I can convert pdf ...
2
votes
1
answer
51
views
Parse subscript and superscript in command
I am using quite a lot of notation in my text.
Thus, I decided to write some commands such as:
\newcommand{\struct}[1]{\mathsf{#1}}
The typical use is as follows:
Let $(\struct{A}_n)$ be a sequence ...
0
votes
0
answers
34
views
Coloring numbers outside string and variables using lstlisting and parsing don't work as expected. Need Help to fix with PDFLaTeX
I am writing my thesis and i need to put extract of code into it. Having developed all my C# code in Visual Studio, I would like to have more or less the same colors, so I have taken different ...
7
votes
3
answers
208
views
Are there any LaTeX commands (including in packages) where the argument will be in math/text mode based on context?
As I work on the parser for finl, I'm contemplating how I'm dealing with command parameters and wondering if my current setup is sufficient.
Right now, a parameter has a type which would either be ...
3
votes
2
answers
108
views
Parse list of tuples
I want to pass a list/sequence of "tuples" to a macro, like this:
\foo {
(value11 value12 value13)
(value21 value22 value23)
(value31 value32 value33)
(value41 value42 ...
1
vote
2
answers
94
views
Gobble the next char if it is whitespace or tilde
I want this macro to gobble the next character in the input stream only if it is whitespace (according to the char code) or it's the tilde character (i.e., a non-breaking space).
My current attempt to ...
4
votes
3
answers
100
views
How to absorb the content of the page into a variable?
This is what I'm trying to do:
\documentclass{article}
\begin{document}
\start
Hello, world!
\stop
\print % here!
\end{document}
I'm expecting Hello, world! to be printed twice. The second time by ...
6
votes
3
answers
274
views
Split string into part by char position
Explanations
I format a moroccan RIB (Relevé d’identité bancaire for “Bank account number”) to display it as a nice rendering. I need to take each part of the RIB to embrace it with a specific label.
...
1
vote
1
answer
55
views
Macro delimited lists
Floats use macro delimited lists like \@freelist. Source2e shows them using macros like \@next and \@cons without showing the definitions. The idea of having self parsing lists is intriguing and ...
1
vote
2
answers
93
views
Automatically composing documents from multiple text files which are not LaTeX formatted?
I'm looking for a way to create a songbook out of individual song files.
Each song file is a self-contained block of text data consisting of:
Song name
Song author
Some details (optional)
Lyrics with ...
9
votes
4
answers
467
views
LaTeX3 - Parsing an argument to apply specific macros
In the following code, I would like to parse the argument of \parseanduse such as to "achieve" the examples shown.
Each time a o is met, the following integer should be used to call the ...
1
vote
1
answer
83
views
ConTeXt: Typeset XML attribute containing newlines
Background
A user can provide their address information in a text area, separating lines by pressing Enter. An XML document is generated, which replaces the new line character with \n, such as in the ...
1
vote
1
answer
128
views
Parsing optional argument from \newenvironment to \newmdenv
I'd like to parse an optional variable from a custom \newenvironment{example} to an mdframed environment \mytextbox nested in the example environment.
What I'd like to achieve is something like
...
5
votes
1
answer
121
views
Parsing a mix of plain text and commands
I am trying to implement a command that parses some expression that can be a mix of plain text, commands with their (any number of) arguments, or even -- if I understood that correctly -- unexpandable ...
7
votes
2
answers
240
views
LaTeX3: Elegant way to forward-reference a counter with a "future" value
I'd like to do, pseudo-code, the following:
\begin{pointtracker}{Advanced Geology}
\begin{itemize}
\item Count the fingers on your left hand. Are there more than 9? \addpoints{1}
\item Draw ...
1
vote
1
answer
40
views
lstlisting: Unexpected newline/missing background color after trailing space in escape section
I'll start with a minimum failing example:
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\lstdefinelanguage{x}{
escapechar={!}
}
\lstset{language=x,
breaklines=true,
...
1
vote
1
answer
429
views
Parsing issues with resume written in LaTeX [closed]
I've written my resume in Overleaf and downloaded it as a PDF to submit to job applications.
For some job applications it works but for others I'm told there is a parsing error (i.e. their automated ...
5
votes
1
answer
149
views
Automatic text highlighting based on a dictionary
I would like to automatically highlight parts of a running text, based on whether the word is in a predefined dictionary, or not. Something along the lines of...
\documentclass{article}
\mydictionary{...
0
votes
2
answers
77
views
Weird 'ProvidesPackage' vs 'newenvironment' macro expansion
currently improving an existing package ('ditaa', based on ditaa0_9.jar) to add support for svg (implemented in ditaa-0.11.0-standalone.jar) yet I'm facing strange macro definition/expansion.
...
11
votes
1
answer
4k
views
is there a python module for parsing LaTeX?
I am looking to write python programs that modify LaTeX source files. To do this I would like to have a basic parser in python that can reliably read and write LaTeX files while maintaining the tree. ...
1
vote
0
answers
69
views
Macro to change the extension of filename
I would like to have a macro to change the extension of a file name. For example, my macro needs to take an argument like Figures/Fig.xxx and return me Figures/Fig0.yyy.
I found a solution in Extract ...
3
votes
2
answers
110
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
4
answers
446
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
0
answers
28
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
1
answer
303
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
1
answer
272
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
3
answers
183
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
2
answers
250
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
1
answer
103
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
0
answers
39
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
1
answer
53
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{\...
27
votes
3
answers
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
1
answer
80
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
2
answers
176
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
0
answers
166
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
1
answer
88
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
1
answer
250
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
1
answer
249
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
0
answers
59
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 ...
1
vote
0
answers
281
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
1
answer
196
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
1
answer
62
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
3
answers
194
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
0
answers
38
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
3
answers
223
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
1
answer
294
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 ...
7
votes
2
answers
3k
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'...