How to convert *.tex files to plain text *.txt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • allynvo206
    New Member
    • Jan 2017
    • 1

    How to convert *.tex files to plain text *.txt

    I don't know where to start for this but I've been looking around and asking and I think i'm supposed to use tokenizers.

    The rules I have to follow are:
    1. Remove all commands backslash followed one or more lowercase letters and terminated with a blank.
    2. Remove all braces: } or {.
    3. Substitute all math display (characters in between $), by the words FORMULA 1
    , FORMULA 2 etc...
    4. The environment ( a special command) .
    \begin{enumerat e}
    \item First item, \fer and only this.
    \item Second line \iterate and maybe more. \item Third.
    ...
    \end{enumerate}
    puts everything between backslash item in a new paragraph with a number. So the
    above should look:
    1. First item and only this.
    2. Second line and maybe more.
    3. Third.
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    You can also use regular expressions. This would be much easier.
    For example, replacing curly brackets and mathematical expressions:

    Code:
    String input = "asdf{{xx{fd}$3*7+5$ab";
    String regEx = "[\\{\\}]";
    String result = input.replaceAll(regEx, "");
    // result = "asdfxxfd$3*7+5$ab"
    
    String regEx = "\\$[^\\$]*?\\$";
    String result2 = result.replaceAll(regEx, "FORMULA");
    // result2 = "asdfxxfd$FORMULA$ab"

    Comment

    Working...