Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TeX directive recognition #2571

Closed
wants to merge 6 commits into from
Closed

Conversation

tyckesak
Copy link
Contributor

This one simple typo—probably left over from some old version—rendered TeX directives like %! TeX program = lualatex useless and prevented Vimtex from recognising directives at all (very annoying!)

It seems likely that this very typo is littered throughout the codebase, but I haven't had the time to establish that; for now at least, it makes TeX directives usable again.

This one simple typo—probably left over from some old version—rendered TeX directives like `%! TeX program = lualatex` useless and prevented Vimtex from recognising directives at all.
@lervag
Copy link
Owner

lervag commented Nov 17, 2022

That's strange. I'm quite sure that tex directives work exactly as intended on my end. Could you provide a concrete, minimal example with a description to show that it does not work? Please include info on your system as well, as it may be relevant.

@lervag
Copy link
Owner

lervag commented Nov 17, 2022

Notice, though, that b:vimtex.tex is the absolute path to the main file of a given project, whereas b:vimtex.base is only the base path, i.e. relative to the root directory. Thus, your proposed change is likely not good without more changes. E.g., if you open a file /path/chapter/1.tex included in a main file /path/main.tex and if you have set autochdir (some people do!), then calling vimtex#parser#preamble(state.base, ...) will fail.

@tyckesak
Copy link
Contributor Author

[...] a concrete, minimal example [...]?

You got it.

We are talking about a MacVim setup on macOS 13.0: typing :version gives

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 24 2021 14:13:28)
macOS version - x86_64
Included patches: 1-3455
Compiled by GitHub Actions
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +file_in_path      -mouse_sysmouse    +tag_binary
+arabic            +find_in_path      +mouse_urxvt       -tag_old_static
+autocmd           +float             +mouse_xterm       -tag_any_white
+autochdir         +folding           +multi_byte        -tcl
-autoservername    -footer            +multi_lang        +termguicolors
+balloon_eval      +fork()            -mzscheme          +terminal
+balloon_eval_term +fullscreen        +netbeans_intg     +terminfo
+browse            +gettext           +num64             +termresponse
++builtin_terms    -hangul_input      +odbeditor         +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              +perl/dyn          +title
+clientserver      +job               +persistent_undo   +toolbar
+clipboard         +jumplist          +popupwin          +transparency
+cmdline_compl     +keymap            +postscript        +user_commands
+cmdline_hist      +lambda            +printer           +vartabs
+cmdline_info      +langmap           +profile           +vertsplit
+comments          +libcall           +python/dyn        +virtualedit
+conceal           +linebreak         +python3/dyn       +visual
+cryptv            +lispindent        +quickfix          +visualextra
+cscope            +listcmds          +reltime           +viminfo
+cursorbind        +localmap          +rightleft         +vreplace
+cursorshape       +lua/dyn           +ruby/dyn          +wildignore
+dialog_con_gui    +menu              +scrollbind        +wildmenu
+diff              +mksession         +signs             +windows
+digraphs          +modify_fname      +smartindent       +writebackup
+dnd               +mouse             -sodium            -X11
-ebcdic            +mouseshape        -sound             -xfontset
+emacs_tags        +mouse_dec         +spell             +xim
+eval              -mouse_gpm         +startuptime       -xpm
+ex_extra          -mouse_jsbterm     +statusline        -xsmp
+extra_search      +mouse_netterm     -sun_workshop      -xterm_clipboard
-farsi             +mouse_sgr         +syntax            -xterm_save

Boom.latex

%! TeX program = lualatex
\documentclass{article}
\directlua{ zzz = 108 }
\begin{document}
Where did that bring you? Back to me.
\end{document}

~/.vimrc

set encoding=utf-8
set nocompatible
call plug#begin('~/.vim/plugs')
Plug 'lervag/vimtex'
call plug#end()

let g:vimtex_syntax_enabled = 1 
let g:vimtex_view_method = 'skim'

Hit \ll and you will be greeted with an error message revealing that the lualatex directive was not taken into account—at all:

Rule 'pdflatex': File changes, etc:
   Changed files, or newly in use since previous run(s):
  Boom.latex
Rule 'pdflatex': The following rules & subrules became out-of-date:
  pdflatex
------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'pdflatex  -file-line-error -synctex=1 -interaction=nonstopmode -recorder  "Boom.latex"'
------------
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex)
 restricted \write18 enabled.

   [...omitted]

./Boom.latex:3: Undefined control sequence.
<recently read> \directlua 
                           
l.3 \directlua
              { zzz = 108 }

./Boom.latex:3: LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.

   [...omitted]

I tracked the bug down to self.tex being the empty string '' instead of anything useful; my gut feeling tells me there should be a reasonable file path there instead. As for how correct my fix is...I admit that it is a rather haphazard one—ignoring the fact that self.base might need the whole path prepended to it—and that I might have been too quick to open a pull request over this, but I'm glad I got your attention over this!

@tyckesak
Copy link
Contributor Author

The first couple lines of the Vimtex log might be interesting to have (before I forget to include it):

Rc files read:
  NONE
Latexmk: This is Latexmk, John Collins, 17 Mar. 2022. Version 4.77, version: 4.77.
======= Need to update make_preview_continuous for target files
Not using a previewer
------------
Running 'echo vimtex_compiler_callback_compiling'
------------
vimtex_compiler_callback_compiling
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': File changes, etc:
   Changed files, or newly in use since previous run(s):
  Boom.latex
Rule 'pdflatex': The following rules & subrules became out-of-date:
  pdflatex
   ...
   ...
   ... [you got the rest]

@lervag
Copy link
Owner

lervag commented Nov 17, 2022

Thanks! Could you also state, explicitly, the steps you take in a terminal?

For me, if I create the specified files, then do vim -u test.vim test.tex, then do \li (or :VimtexInfo), I get this:

...
VimTeX project: test
  base: test.tex
  root: /home/lervag/test
  tex: /home/lervag/test/test.tex
  main parser: current file verified
  document class: article
  compiler: latexmk
    engine: -lualatex
    ...

@tyckesak
Copy link
Contributor Author

tyckesak commented Nov 17, 2022

Done.

~ % cd Garage/Literacy/VimtexPlayground
VimtexPlayground % mvim Boom.latex

@tyckesak
Copy link
Contributor Author

And :VimtexInfo gives

System info:
  OS: macOS 13.0 (22A380)
  Vim version: VIM 8.2 (1-3455)
  Has clientserver: true
  Servername: VIM2

VimTeX project: Boom
  base: Boom.latex
  root: /Users/josip/Garage/Literacy/VimtexPlayground
  tex: 
  main parser: current file verified
  document class: 
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Skim
  qf method: LaTeX logfile

@lervag
Copy link
Owner

lervag commented Nov 17, 2022

Ok. Does this mean that you apply the minimal configuration as your regular .vimrc file? Notice that it is usually more convenient to make a test.vim file similar to the one your provide in a separate directory, then use mvim -u test.vim test.tex; this way, you don't need to change your regular config.

The :VimtexInfo output shows the main problem here, which is that the tex property is empty. That should not happen, and this is the issue. We need to figure out why it happens. The first place to look is here:

let l:new.tex = index(['tex', 'dtx', 'tikz', 'ins'], l:ext) >= 0
\ ? a:main : ''

Considering that you've opened a PR and already know at least something about working with Vimscript, perhaps you could investigate on your side by e.g. adding unsilent echo "DBG" a:main above, and perhaps also checking the value of the function arguments before passing them to the #new function?

@tyckesak
Copy link
Contributor Author

Does this mean that you apply the minimal configuration as your regular .vimrc file?

Not at all; I use a more extensive one.

[...] then use mvim -u test.vim test.tex [...]

perhaps you could investigate on your side by e.g. adding unsilent echo "DBG" a:main above

Good pointers, thanks! I thought for sure no one could possibly be debugging Vimscript like I have for this; I'll look into it. If you don't hear by Sunday evening CET, I might have forgot or put this off.

@lervag
Copy link
Owner

lervag commented Nov 17, 2022

Sounds good! I would not be very surprised if the problem is related to your configuration somehow, but I'm not sure. It may be a bug, and I'll be happy to help figure things out!

Turns out Vimtex did not recognise files ending in ‘.latex’ which
might be the preferred ending for some; neither for ‘.tex’
and ‘.tikz’ if cased differently
@tyckesak
Copy link
Contributor Author

tyckesak commented Nov 26, 2022

I have put fixing this off for a week; turned out that your code reference was exactly what needed fixing! The old “bugfix” is no more, and replaced with another. This time however, we don't need to worry about breakage anymore.

Edit: hold off another minute; found a typo of my own. How embarrassing.

@lervag
Copy link
Owner

lervag commented Nov 27, 2022

Thanks, I agree, this seems to be a relevant fix. I proposed another minor fix and adjustment and will merge when that's applied.

autoload/vimtex/state/class.vim Outdated Show resolved Hide resolved
Changes requested by higher power.
@tyckesak tyckesak requested a review from lervag November 27, 2022 16:54
lervag pushed a commit that referenced this pull request Nov 27, 2022
Turns out Vimtex did not recognise files ending in ‘.latex’ which
might be the preferred ending for some; neither for ‘.tex’
and ‘.tikz’ if cased differently

Includes changes requested by higher power during PR review.

refer: #2571
@lervag
Copy link
Owner

lervag commented Nov 27, 2022

Thanks! Looks fine now! I took the liberty of squashing your commits on top of master to keep a cleaner Git history.

@lervag lervag closed this Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants