Home Download Buy Blog Forum Support

ST2: build system's file_regex for LaTeX

ST2: build system's file_regex for LaTeX

Postby wledoux on Wed Mar 23, 2011 5:58 pm

Hi,

As I did not suceed to make the LaTeX pIugin work with SublimeText2, I am trying to make a build system for running pdflatex on my LaTeX files.
So far it is correctly running the command pdflatex, but I would need some help for making the regex that would parse the messy log and capture the file and the line of the error.

I read both of the following help pages (that I had a hard time to find, btw)
http://sublimetext.info/docs/core/build_systems.html
http://sublimetext.info/docs/reference/ ... stems.html

I don't see how I could make a regex for a pdflatex output.
For a simple sample, with a file Main.tex including a file SubNOTWorking.tex that contains an error, and that includes before the error a file subsubWorking.tex, the ouput looks like that:
Code: Select all
This is pdfTeX, Version 3.1415926-1.40.11 (MiKTeX 2.9)
entering extended mode
(Q:/@Documents/PathGenTechnicalDoc/main.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, afrikaans, [...], loaded.
(Q:\@Documents\PathGenTechnicalDoc\SubNOTWorking.tex
(Q:\@Documents\PathGenTechnicalDoc\SubSubWorking.tex
("C:\Progs32\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
("C:\Progs32\MiKTeX 2.9\tex\latex\base\size12.clo"))
No file main.aux.
)
! Undefined control sequence.
l.12 \secddtion
               {Formulae; inline vs. displayed}
?
! Emergency stop.
l.12 \secddtion
               {Formulae; inline vs. displayed}
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on main.log.
[Finished]


For what I understood:
  • A '(' is opened for each compiled file and closed after the compilation of this file is completed.
  • If a file includes several others, the '(' of each are nested.
  • for each error, the file name is not repeated, and the line starts with l.## with ## being the line number.
  • the column is expressed by an "end of line" at the place where the error occured, so it should require to count the number of characters before the end of line.

As memorizing and counting are two things that regex are not very good at (AFAIK), I guess I should make another program that would wrap the call to pdflatex and modify the output with a command similar to sed or awk, but I hope for someone having a simpler suggestion.

Thanks for this great tool !
wledoux
 
Posts: 17
Joined: Wed Mar 23, 2011 5:29 pm

Re: ST2: build system's file_regex for LaTeX

Postby Marciano on Wed Mar 23, 2011 8:18 pm

Hi,

I am porting my ST1 LaTeX plugin to ST2. It's actually relatively stable, but undocumented. Still, if you'd like to see what I have:

git://github.com/msiniscalchi/LaTeX-ST2.git

You can either pull it in, or download a .zip from Github and unzip it somewhere in your Packages directory. Note that, unlike the ST1 version, this is supposed to live in a separate directory from the one with the LaTeX snippets that come with ST.

There is a working build system for Windows and OSX. Also, backward and forward searhc work perfectly, but you need to look at the files to see how to configure Sumatra (Win) / Skim (OSX) to make it work. Forward search is bound to alt+shift+j (win) / cmd+shift+j (osx). The new ref / cite support is MUCH better than in ST1, as is the new completion system (courtesy of ST2's awesome completions api).

Your feedback is very welcome! Again, the above is very much in progress AND not documented at all. I hope to be able to upload some docs soon, but...
Marciano
 
Posts: 143
Joined: Fri Sep 18, 2009 2:55 am

Re: ST2: build system's file_regex for LaTeX

Postby wledoux on Wed Mar 23, 2011 10:48 pm

Hi,

Thanks for pointing me to your work !

First let's talk about this system-build thing, then i'll give you my feedback !
  • You used the -file-line-error to get a more regex-friendly ouput. The only sad thing with that is that you don't have the hint about where the error is on the line anymore , and that's kind of annoying when you have very large lines, takings dozens of lines on your screen, and you have to find the tiny error into that, based on a laconic "undefined control sequence" hint from pdflatex! That's why I was trying to parse the original log.
    Anyway, I don't know if there is much we can do about that, the output format of pdflatex really sucks, don't you think ?
  • Also, when I tried to use this option, I was stuck with pdflatex wrapping the output to 80 cols ! It seems that --max-print-line=200 do the job, I did not know that one ! Thanks !

About your plugin more generally:
  • I think that there is several parameters in the build process, and maybe in other commands, that any user would like to set. I don't know if ST2 would allow a kind of per-plugin configuration file so that the end-user can tweak a plugin without getting its hand into the core.
    For example, choosing to add a '-c' option to the build command so that it cleans the intermediate files. Or another really usefull thing would be to add some per-project path to be included '-I'. I know that I should be able to do it through the env variable TEXINPUTS, but for a specific project include, it may be useful.
  • Generally, I don't know how to do it, but being able to set a per-project variable and to use it into plugins or system build would be nice.
    For example, I don't wan't the currently edited file to be compiled when I press F7 (btw, the system build blindly try to run texify on the current file, no matter its extension), I want it to be Master.tex for my project A and Main.tex for my projectB, always. Do you think it's possible in ST2 ? It was done by textmate with a variable specific to the project called "TM_MASTERFILE" or something similar.
  • Forward and Backward search is working just fine after configuring sumatra, (however, ST2 is crashing when you press alt+shift+j and sumatra is not installed ^^). I took a custom version of sumatra (http://william.famille-blum.org/softwar ... index.html) where you can set your favorite text editor for Inverse Search in the settings, whereas it was not possible in the version I downloaded on the official website. (for potential readers, the instructions to make forward search work are in viewPDF.py).
  • As I am very very new to ST2, I did not found how to run the other scripts that you provided (except F7 and alt shift j that you gave me). Is there a menu from where I can run the commands provided by a plugin, or do I have to find and learn all the shortcuts ? How can I launch them from the console ?
  • It is sad that sumatra takes the focus when you launch it, if it was not, you could almost refresh periodically the PDF as you type, I saw that you are thinking about this on your blog, it would be just great !

Thanks again for you work, I'll use it and let you know if I come up with interesting changes.

PS: Do you happen to know how to use the "env" parameter of system build ? I am trying to use it to add a TEXINPUTS environnement variable to texify, but it does not seems to work.
wledoux
 
Posts: 17
Joined: Wed Mar 23, 2011 5:29 pm

Re: ST2: build system's file_regex for LaTeX

Postby Marciano on Thu Mar 24, 2011 1:35 am

Hi,

here are a few answers to your questions, in the order you asked them.

First of all, as a general comment, the standard way to use the build system is not flexible enough to accommodate tex's many quirks (including its abysmal error reporting). However, jps added a fantastic feature to ST2: you can direct the build system to invoke ANY ST command, rather than "exec" (explanation: if you set up a build system wiht "make" as the "cmd", what happens behind the curtains is that ST2 invokes "exec" with "make" as parameter).

In the near future, I plan to take advantage of this feature (I actually asked jps for it, along with the OS-dependent configuration option, so I'd better put my code where my mouth is!). I will write a ST command that invokes whatever OS-specific code is required (texify on WIndows, latexmk on OSX and Linux), then parses the output, places it in the output panel in a NICELY FORMATTED way (as in: file:line:col, where the column is "guessed" based on tex's error reporting) so you can F4 to each error as in any civilized programming language :-)

This may also take care of the PDF viewer focus issue, or at least it gives me more flexibility to launch the previewer in an appropriate way.

Finally, all the configuration options you mention (master file, clean intermediate files or not etc.) cannot be handled by the build system, but CAN be handled by a purpose-made ST command. I am NOT promising that I will implement all the tweaks you suggest, but I'll take note of them :-)

1. See above.
2. Yep, that's a useful option.
3. See above
4. See above
5. First, the version you downloaded is probably very old. I am running the stock 1.4 version of Sumatra, and it does have a nice configuration option for inverse search. Second, definitely ST2 should not crash when Sumatra is not installed! I must do some error-checking, either in that command or perhaps when the plugin is loaded ("sanity check"). Right now there's none of that. At the very least, I should have some kind of warning in the documentation.
6. As I said, unfortunately there is no documentation yet. I just provided you with a link to the git repository in the hope that it might be useful, but this thing is not ready for public consumption. Anyway, open the .sublime-keymap file in the plugin directory; that will give you the few available keybinding. I'm really trying to work mostly with the completion system (hence the ref and cite commands, and the math macros).
7. Yep, fully agree---see above.
4.
Marciano
 
Posts: 143
Joined: Fri Sep 18, 2009 2:55 am

Re: ST2: build system's file_regex for LaTeX

Postby wledoux on Thu Mar 24, 2011 8:40 am

Hi again,

Just in case you did not notice, when the error occurs quite far from the begginning of the line, the ouput of pdftex will cut the beggining of the line and put "..." instead. Then for guessing the column in this case you would need to try a regex-matching on the line instead of just counting characters.

I will definitly follow your work.

If I want to help, can you explain me in what way a specific ST command could handle configuration options (I mean how would they be defined per project, and how the command can access to them and use them) ?
wledoux
 
Posts: 17
Joined: Wed Mar 23, 2011 5:29 pm

Re: ST2: build system's file_regex for LaTeX

Postby Marciano on Thu Mar 24, 2011 9:27 pm

Yes, I am familiar with (as in, "have learned to hate") tex's error reporting... Many times, it's useless, but often you can use the line break to find the error. That's what I'm planning to do. Please be patient :-)

Regarding the configuration options, I'm not quite sure yet, because I haven't looked at ST2's project system yet. But, the point is that, once you can invoke an arbitrary python command, you have access to the excellent ST2 API, and hence---for instance---retrieve values from configuration files.
Marciano
 
Posts: 143
Joined: Fri Sep 18, 2009 2:55 am


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 18 guests

cron