I use (g)vim to edit both context and latex files. Unfortunately, both of them usually have *.tex extension. This mean that detecting filetype from extension is not possible, so one should look into the contents of the file to see if it a context file or not. I am planning to submit a ftdetect for context to vim. Right now, I check if the first six lines of the file contain any of '\\start\|\\enablemode\|\\unprotect\|\\setvariables\|\\module\|\\usemodule' and if so, set the filetype to context, otherwise it is set to tex (that loads latex plugins). This works for my context writing style. I would like to know about other people's preference. 1. Do you write some keyword unique to context in the first few lines of the file. Should I also check the last few line lines. 2. Are there any other keywords that you will like to include. 3. Is it enough to check the first 6 line or should I check more. I do not want to check more lines as this will make the detection slower (by a few mili secs). Thanks, Aditya -- Aditya Mahajan, EECS Systems, University of Michigan http://www.eecs.umich.edu/~adityam || Ph: 7342624008
Thomas A. Schmitz wrote:
% interface=en language=nl program=pdfetex etc, the following are understood by texexec ['tex','texengine'], ['program','texengine'], ['translate','tcxfilter'], ['tcx','tcxfilter'], ['output','backend'], ['mode','mode'], ['ctx','ctxfile'], ['version','contextversion'], ['format','texformats'], ['interface','texformats']
Hans
Taco Hoekwater wrote:
the ruby version of texexec can handle that (if i did it right); Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Aditya Mahajan wrote:
her eis the ruby method used in newtexexec: def scantexcontent(filename) if FileTest.file?(filename) and tex = File.open(filename) then while str = tex.gets do case str.chomp when /^\%/o then # next when /\\(starttekst|stoptekst|startonderdeel|startdocument|startoverzicht)/o then setvariable('texformats','nl') ; break when /\\(stelle|verwende|umgebung|benutze)/o then setvariable('texformats','de') ; break when /\\(stel|gebruik|omgeving)/o then setvariable('texformats','nl') ; break when /\\(use|setup|environment)/o then setvariable('texformats','en') ; break when /\\(usa|imposta|ambiente)/o then setvariable('texformats','it') ; break when /(height|width|style)=/o then setvariable('texformats','en') ; break when /(hoehe|breite|schrift)=/o then setvariable('texformats','de') ; break when /(hoogte|breedte|letter)=/o then setvariable('texformats','nl') ; break when /(altezza|ampiezza|stile)=/o then setvariable('texformats','it') ; break when /externfiguur/o then setvariable('texformats','nl') ; break when /externalfigure/o then setvariable('texformats','en') ; break when /externeabbildung/o then setvariable('texformats','de') ; break when /figuraesterna/o then setvariable('texformats','it') ; break end end tex.close end end ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2/2/06, Aditya Mahajan wrote:
\enableregime, \setupoutput Is \setup too general (will it recognize any LaTeX document)? I don't know how slow/fast the detection is since I only use short files, but if you check the last few lines, \stoptext (together with its international alternatives) isn't a bad idea. Also, if you check the last few lines: emacs users usually put some lines of code at the end to mark the document as being written in ConTeXt.
2. Are there any other keywords that you will like to include.
A keyword like set tex_preferred_dialect=latex/context :) and then if tex_preferred_dialect == context if the first few lines contain \documentclass or \documentstyle, declare it latex, otherwise ConTeXt else [your script]: if the first line contains % tex= or any keywords that Hans sent or if the first six lines contain the keywords you suggested (together with international alternatives) (don't take that suggestion too seriously) Mojca
<--- On Feb 4, Mojca Miklavec wrote --->
That is the main trouble. In principle, you can have latex document with \starttext as the first line. But most usual tex files do not have it. I have not seen a latex macro with \setup. So, I will include that also.
The file may not necessarily end with \stoptext. It can be \stopcomponent, \stopproduct, \stopproject, \stopenvironment. Anything else?
Ah, compatibility with Emacs. I will look at that later ;)
I looked it up and it seems that g:Tex_Flavor is meant for this kind of thing.
Actually, this may not be too hard to implement. Let me have a look at this, and I will get back to you when there is something working. Aditya -- Aditya Mahajan, EECS Systems, University of Michigan http://www.eecs.umich.edu/~adityam || Ph: 7342624008
<--- On Feb 10, Aditya Mahajan wrote --->
This is the else part of the script (modified from Hans ruby code to vimL). I tested it on the sources of the manuals, and the only thing that it could not detect correctly was metafun/mfun-ef.tex. Looking at that file, I do not think that it contains any context specific keyword. Can others test on their context projects and see if this works correctly. I do not know the itnernational alternatives of all the commands. If your document uses any of those, let me know. Also check your latex documents to see that the script does not recognise it as context. To run the script, save it as identify.vim . Inside vim, :source identify.vim :cd directory containing tex files :argadd *.tex :redir @a :argdo call Identify_ConTeXt() :redir END :e temp_file :put a Now you have all the vim messages in temp_file :g!/ConTeXt/d Get rid of lines not containing context. The message format from the script is filename ConTeXt not detected/ detected at line ... format (en|nl|de|it) Here is the script """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " A bit more detailed evaluation for english. \\set and \\use may be too " ambiguous. Checking for setvariables and use encoding let g:ConTeXt_en = \ '\\\(starttext\|startproject\|startproduct\|startcomponent\|startenvironment'. \ '\|enablemode\|enableregime\|setvariables\|useencoding\|setup' . \ '\|starttypescript' . \ '\|usemodule\|externalfigure\)' let g:ConTeXt_nl = \ '\\\(starttekst\|startprodukt\|startprojekt\|startonderdeel\|startdocument\|startoverzicht'. \ '\|stel\|gebruik\|omgeving' . \ '\|externfiguur\)' let g:ConTeXt_de = \ '\\\(stelle\|verwende\|umgebung\|benutze' . \ '\|externeabbildung\)' let g:ConTeXt_it = \ '\\\(usa\|imposta\|ambiente' . \ '\|figuraesterna\)' let g:ConTeXt_generic = \ '\\\(protect\|unprotect\|startmode\|mainlanguage\)' function! Identify_ConTeXt() let g:ConTeXt_texformat = "" let l:last_line_num = line('$') let l:curr_line_num = 1 while l:curr_line_num <= l:last_line_num let l:curr_line = getline(l:curr_line_num) if l:curr_line !~ '^%' if l:curr_line =~ g:ConTeXt_en let g:ConTeXt_texformat = 'en' break endif if l:curr_line =~ g:ConTeXt_generic let g:ConTeXt_texformat = 'generic' endif if l:curr_line =~ g:ConTeXt_nl let g:ConTeXt_texformat = 'nl' break endif if l:curr_line =~ g:ConTeXt_de let g:ConTeXt_texformat = 'de' break endif if l:curr_line =~ g:ConTeXt_it let g:ConTeXt_texformat = 'it' break endif endif let l:curr_line_num = l:curr_line_num + 1 endwhile if g:ConTeXt_texformat == "" echo bufname("%") . ' ConTeXt not detected!' else echo bufname("%") . ' ConTeXt detected at line ' . l:curr_line_num . \ ' format: ' . g:ConTeXt_texformat endif endf """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -- Aditya Mahajan, EECS Systems, University of Michigan http://www.eecs.umich.edu/~adityam || Ph: 7342624008
participants (5)
-
Aditya Mahajan
-
Hans Hagen
-
Mojca Miklavec
-
Taco Hoekwater
-
Thomas A. Schmitz