4

In a complex project, TeX is typically working on many different included files. In the .log file, file inclusion is indicated by (<filename> ... ). If such stanzas are long, and possibly nested, it is not easy to see which file inclusions are surrounding a given log entry. Indentation could solve this problem in an elegant and standard way.

Is there any way to enforce indentation in TeX's log file? Or has anybody written a script to post-process log files, according to nested (...) stanzas?

1 Answer 1

3

This simple code is working for me.

#include<string.h>
#include<iostream>
#include <fstream>
using namespace std;

int main(int argc, char *argv[]){
    const char* outFile="indented.log";
    const char *pad="\t", *inFile;

    if(argc==3){
        inFile=argv[1];
        outFile=argv[2];
    }
    else if(argc==2)
        inFile=argv[1];
    else{
        cout<<"arg0: log file, arg1: optional outfile"<<endl;
        return 0;
    }

    char ch;
    ifstream fin(inFile, fstream::in);
    ofstream out (outFile);
    int lenpad = strlen(pad);

    int indent = -1; // Miss one indentaion
    while (fin >> noskipws >> ch) {
        out.put(ch);
        if(ch == '(')   indent++;
        else if(ch == ')')   indent--;
        else if(ch == '\n'){
            for(int j=0; j<indent; j++){
                for(int i=0; i<lenpad; i++){
                    out.put(pad[i]);
                }
            }
        }
    }
    fin.close();
    out.close();
    cout<<"Output written to file "<<outFile<<endl;
    return 0;
}
1
  • Wow! After one year such a good answer. I just tested it on a complicated 100-page manual, and it worked perfectly. Thanks a lot!
    – Joachim W
    May 29, 2016 at 12:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .