Thread: [Vim-latex-devel] Script to fix compiler error messages for VIM-LaTeX
Brought to you by:
srinathava,
tmaas
From: Ted P. <te...@te...> - 2008-03-07 15:10:11
|
It's well-known (yet not often discussed) that Vim has a hard time parsing LaTeX error messages because they are nested within parentheses, and multiple nests can closed on a single line (e.g., you can find ")))" on a single line). When these nest closings do not get parsed correctly by Vim, then Vim-LaTeX will open the wrong file when it encounters an error. I've put together a wrapper (implemented with bash) to filter latex error messages to fix this problem: http://links.tedpavlic.com/shell_scripts/vimlatex I've also posted this script at vim.org. I've put some additional information at: http://phaseportrait.blogspot.com/2008/03/fixing-vim-latex-compiler-error.html At least one other similar script exists on the web. However, because bash pipelines return the rightmost return code, those scripts often require writing to a temporary file in order for the wrapper to return whatever latex returns. My script uses a bash file descriptor trick to get around using temporary files. I hope this is helpful to someone. --Ted -- Ted Pavlic <te...@te...> |
From: Christian E. <bla...@gm...> - 2008-03-07 17:14:49
|
Hi Ted, * Ted Pavlic on Friday, March 07, 2008 at 10:10:05 -0500 > It's well-known (yet not often discussed) that Vim has a hard time > parsing LaTeX error messages because they are nested within parentheses, > and multiple nests can closed on a single line (e.g., you can find ")))" > on a single line). When these nest closings do not get parsed correctly > by Vim, then Vim-LaTeX will open the wrong file when it encounters an > error. > > > I've put together a wrapper (implemented with bash) to filter latex > error messages to fix this problem: > > http://links.tedpavlic.com/shell_scripts/vimlatex Very neat! Thanks for your efforts at keeping vim-latex alive anyway. How about: --- vimlatex.orig 2008-03-07 18:03:11.000000000 +0100 +++ vimlatex 2008-03-07 18:07:20.000000000 +0100 @@ -41,7 +41,8 @@ shift exec 3>&1 -retcode=$( exec 4>&1; { ${texprg} "$@"; echo $? >&4; } | sed -e "s/(/\n(/g" | sed -e "s/)/)\n/g" | sed -e "/[0-9]\+$/{N;s/\n\([0-9]\+\)/\1/;}" >&3) +retcode=$( exec 4>&1; { ${texprg} "$@"; echo $? >&4; } \ +| sed -e "s/(/\n(/g" -e "s/)/)\n/g" -e "/[0-9]\+$/{N;s/\n\([0-9]\+\)/\1/;}" >&3) exec 3>&- exit ${retcode} Instead of piping through several sed instances, repeat -e -- The line continuation is personal taste. Or have you already tried this, and it breaks? c -- _B A U S T E L L E N_ lesen! --->> <http://www.blacktrash.org/baustellen.html> |
From: Ted P. <te...@te...> - 2008-03-07 17:48:54
|
Christian -- That's an EXCELLENT suggestion. I've implemented it and updated all on-line versions (with credit to you in the comments/version history). Thanks! -- Ted > Instead of piping through several sed instances, repeat -e -- The > line continuation is personal taste. > > Or have you already tried this, and it breaks? -- Ted Pavlic <te...@te...> |
From: Christian E. <bla...@gm...> - 2008-03-07 19:07:24
|
Ted, * Ted Pavlic on Friday, March 07, 2008 at 12:48:46 -0500 [ replace pipe thru sed instances by several -e ] > That's an EXCELLENT suggestion. I've implemented it and updated all > on-line versions (with credit to you in the comments/version history). Heh, I'm flattered. Note, however, that by using sed you encounter portability issues! For me, on MacOS 10.4.11, the script only works because I have GNU Sed (gsed) installed. Apple shipped sed in /usr/bin can't handle "\n". For portability you might want to wrap this in python or perl. c -- _B A U S T E L L E N_ lesen! --->> <http://www.blacktrash.org/baustellen.html> |
From: Ted P. <te...@te...> - 2008-03-07 19:25:03
|
> Note, however, that by using sed you encounter portability > issues! For me, on MacOS 10.4.11, the script only works because I > have GNU Sed (gsed) installed. Apple shipped sed in /usr/bin > can't handle "\n". > > For portability you might want to wrap this in python or perl. Another good point. However, does OS/X ship with python or perl standard? For portability, I think I'd want to use a utility standard with them all. I may just have to suck it up and encode a newline (rather than a \n) in the script (and stick with sed). :( Thoughts? Thanks -- Ted -- Ted Pavlic <te...@te...> |
From: Christian E. <bla...@gm...> - 2008-03-07 20:29:49
|
* Ted Pavlic on Friday, March 07, 2008 at 14:39:10 -0500 > Here's an interesting solution... > > http://www.culmination.org/2008/02/10/sed-on-mac-os-x-105-leopard/ Indeed. > Use: > > \\”$’\n’”\ > > instead. > > I'll make that change and update. I'm eager to know how you do it. I get ": unescaped newline inside substitute pattern Also, IIRC, you have to use [0-9][0-9]* instead of [0-9]\+. [0-9]\{1,\} works on MacOS, but breaks on other machines. c -- _B A U S T E L L E N_ lesen! --->> <http://www.blacktrash.org/baustellen.html> |
From: Christian E. <bla...@gm...> - 2008-03-07 22:43:53
|
Hi Ted, * Ted Pavlic on Friday, March 07, 2008 at 17:00:04 -0500 > Check out the solution at: > > http://links.tedpavlic.com/shell_scripts/vimlatex Very neat. > I implemented the sed scripts with single quotes to help make the > "trick" documented on that page a little more clear. Yup. You beat me to it. Single quotes are much easier to handle as long as you don't /have/ to use double quotes. > The "trick" puts a "\" at the end of the sed script and then inserts a > NEWLINE right in the middle of the string. The "\" somehow tells the > shell (or sed) to continue to the next line before assembling the string. > > So, really all you need is something like... > > sed -e 's/blah/\'$'\n''stuff/' > > which will replace "blah" with a newline and then "stuff". Thanks for clarifying. > Hopefully that will do it. Works like a charm with both Apple shipped sed and gsed. > Side notes: > > 1. The OS/X sed has no trouble MATCHING a newline with \n) Ah, right. > 2. I changed the ORDER of the search strings. I also added a SECOND > search string for catching numbers split across lines. It's meant to > catch lines like: > > things 12 > 34 stuff 56 > 78 other things > > Now, if that pattern continues, it will miss a few. I'm hoping that just > catching three lines in a row will be sufficient. A better solution > would be to use perl... but I don't know what's included with OS/X > without installing the developer tools. :( Python and Perl are included; the libs are in a non-standard location: /Library/Perl/... But for for executing scripts you should be fine. Still for these tasks sed and awk are way cooler and faster. c -- __ _ _ _ __ _ _ \ \ | |__| |__ _ __| |_\ \| |_ _ _ __ _ __| |_ \ \| '_ \ / _` / _| / /\ \ _| '_/ _` (_-< ' \ http://www.blacktrash.org/ \_\_.__/_\__,_\__|_\_\ \_\__|_| \__,_/__/_||_| Jabber-ID: bla...@gm... |
From: Ted P. <te...@te...> - 2008-03-07 19:39:20
|
Here's an interesting solution... http://www.culmination.org/2008/02/10/sed-on-mac-os-x-105-leopard/ Use: \\”$’\n’”\ instead. I'll make that change and update. Thanks! --Ted Ted Pavlic wrote: >> Note, however, that by using sed you encounter portability >> issues! For me, on MacOS 10.4.11, the script only works because I >> have GNU Sed (gsed) installed. Apple shipped sed in /usr/bin >> can't handle "\n". >> >> For portability you might want to wrap this in python or perl. > > Another good point. However, does OS/X ship with python or perl > standard? For portability, I think I'd want to use a utility standard > with them all. > > I may just have to suck it up and encode a newline (rather than a \n) in > the script (and stick with sed). :( > > Thoughts? > > Thanks -- > Ted > > > -- Ted Pavlic <te...@te...> |
From: Ted P. <te...@te...> - 2008-03-07 22:00:22
|
Check out the solution at: http://links.tedpavlic.com/shell_scripts/vimlatex I implemented the sed scripts with single quotes to help make the "trick" documented on that page a little more clear. The "trick" puts a "\" at the end of the sed script and then inserts a NEWLINE right in the middle of the string. The "\" somehow tells the shell (or sed) to continue to the next line before assembling the string. So, really all you need is something like... sed -e 's/blah/\'$'\n''stuff/' which will replace "blah" with a newline and then "stuff". Hopefully that will do it. Side notes: 1. The OS/X sed has no trouble MATCHING a newline with \n) 2. I changed the ORDER of the search strings. I also added a SECOND search string for catching numbers split across lines. It's meant to catch lines like: things 12 34 stuff 56 78 other things Now, if that pattern continues, it will miss a few. I'm hoping that just catching three lines in a row will be sufficient. A better solution would be to use perl... but I don't know what's included with OS/X without installing the developer tools. :( Thanks, again -- Ted Christian Ebert wrote: > * Ted Pavlic on Friday, March 07, 2008 at 14:39:10 -0500 >> Here's an interesting solution... >> >> http://www.culmination.org/2008/02/10/sed-on-mac-os-x-105-leopard/ > > Indeed. > >> Use: >> >> \\”$’\n’”\ >> >> instead. >> >> I'll make that change and update. > > I'm eager to know how you do it. > > I get > ": unescaped newline inside substitute pattern > > Also, IIRC, you have to use [0-9][0-9]* instead of [0-9]\+. > [0-9]\{1,\} works on MacOS, but breaks on other machines. > > c -- Ted Pavlic <te...@te...> |
From: Ted P. <te...@te...> - 2008-03-08 20:34:34
|
> Python and Perl are included; the libs are in a non-standard > location: /Library/Perl/... But for for executing scripts you > should be fine. Still for these tasks sed and awk are way cooler > and faster. So, in your opinion, it's probably rare that line numbers will be broken across two lines THREE times in a row, and so I should just leave things as they are. A single instance of sed (running four search/replace scripts) is better than a full blown Perl (or Python, eek!). Great, then. Thanks for your help! -- Ted -- Ted Pavlic <te...@te...> |
From: Christian E. <bla...@gm...> - 2008-03-09 07:27:08
|
* Ted Pavlic on Saturday, March 08, 2008 at 15:34:11 -0500 >> Python and Perl are included; the libs are in a non-standard >> location: /Library/Perl/... But for for executing scripts you >> should be fine. Still for these tasks sed and awk are way cooler >> and faster. > > So, in your opinion, it's probably rare that line numbers will be broken > across two lines THREE times in a row, You wait 'till all those complaints flood in ;) > and so I should just leave things as they are. A single > instance of sed (running four search/replace scripts) is better > than a full blown Perl (or Python, eek!). It surely is faster -- and I like the dirty newline workaround for sed. As I am saying "newline", I wouldn't know what happens on a windows machine. Another alternative worth looking into might be to offer something with Vim's builtin Perl/Python (Vim-LaTeX already has some Python stuff) in case Vim is compiled with +python or +perl. I might look into the Python side if I find time (and when I actually understand some of what your script does ;) ), as you don't seem to like py, hehe. c -- _B A U S T E L L E N_ lesen! --->> <http://www.blacktrash.org/baustellen.html> |
From: Christian E. <bla...@gm...> - 2008-03-10 11:36:51
|
* Ted Pavlic on Saturday, March 08, 2008 at 15:34:11 -0500 > So, in your opinion, it's probably rare that line numbers will be broken > across two lines THREE times in a row, and so I should just leave things > as they are. A single instance of sed (running four search/replace > scripts) is better than a full blown Perl (or Python, eek!). I haven't had any problems, but watching the output I sometimes see things like: [1{/Users/chris/.texmf- var/fonts/map/pdftex/updmap/pdftex.map}] Just to let you know, I'm not sure whether Vim-LaTeX actually consults those broken lines, and, if yes, handles them correctly already. I'd have to dive into the Vim-LaTeX code to be sure, and am too lazy atm. Thanks again for the script. c -- LaTeX package to set verse flush right on overrun: <http://www.blacktrash.org/hg/foverse/> |