Reputation: 5419
What are the required and recommended tools (e.g. using java) to create an "interpreter" which generates latex source files from textfiles (which have an own syntax)?
example:
This is a list of items:
* first
* second
* third
should generate a compilable *.tex file containing
This is a list of items:
\begin{itemize}
\item first
\item second
\item third
\end{itemize}
Upvotes: 1
Views: 379
Reputation: 1616
What your are trying to develop is called a parser. The first thing to do when developing a parser is to determine the formal grammar (ie the syntax rules that the input file has to follow) of the files you want to parse. Formal grammars are usually expressed in EBNF. For instance, a formal grammar for the lists of items contained in your textfiles could be :
list = { list_element } ;
list_element = *, " ", {" "}, {all_characters} ;
all_characters = ? all visible characters ? ;
If the grammar of the files you want to parse is regular (ie without recursion), you can simply parse your file using regular expressions (Although they may become complicated).
The other option, which will work even if your grammar is not regular, is to use a parser generator. Parser generators take your formal grammar and generate a program able to parse input files respecting your grammar and generate an abstract syntax tree representing the input file which you can use to generate the output file (finally !). The most common parsers generators in Java are javacc and ANTLR (Although they are more).
The theory being parsing is rather complicated but usage of parser generators is much simpler that it sounds. So concretely, my advice would be to :
And you should be able to generate tex files from your textfiles.
Upvotes: 5