donraphaco / neotex Goto Github PK
View Code? Open in Web Editor NEWlatex live preview - plugin for neovim and vim 8
License: MIT License
latex live preview - plugin for neovim and vim 8
License: MIT License
NeoTex doesn't work in neovim on windows (running a build from late march 2017).
Turns out, that the file path of the temporary file ( tempname() ) is not affected by
set shellslash
which should make paths use a forward slash instead of the windows backslash. A pathname such as C:\ble\rex.tex causes errors, while C:/ble/rex.tex is ok.
using
expand(tempname())
seems to be a solution, the following patch fixes this
---
ftplugin/tex.vim | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ftplugin/tex.vim b/ftplugin/tex.vim
index 4172163..d1d9bcb 100644
--- a/ftplugin/tex.vim
+++ b/ftplugin/tex.vim
@@ -3,9 +3,9 @@ if !get(g:, 'neotex_enabled', 1)
endif
if !exists('s:neotex_loaded')
- let s:neotex_buffer_tempname = tempname()
+ let s:neotex_buffer_tempname = expand(tempname())
if get(g:, 'neotex_latexdiff', 0)
- let s:neotex_preview_tempname = tempname()
+ let s:neotex_preview_tempname = expand(tempname())
else
let s:neotex_preview_tempname = s:neotex_buffer_tempname
endif
--
If the pathname of your .tex file has a space the plugin fails to change the directory and then never gets to compiling the latex code. I've created a patch cless/neotex@2c3f26f and while that works it's probably not an ideal way to go about solving this issue.
I'm guessing vim passes the b:neotex_jobexe
to the current shell, and I guess that means that how you escape your string depends heavily on your environment. Can the job be executed from python instead, using the subprocess api, or is there a special reason that it needs to be done from vimscript?
I need to render file with Chinese characters.
First of all, thank you for making this plugin.
I would like to suggest you the implementation of synctex forward search. I've managed to get it working, but its far from good.
Here is my modified version of tex.vim
:
if !get(g:, 'neotex_enabled', 1)
finish
endif
if !exists('s:neotex_loaded')
if !has('timers')
echohl Error | echomsg 'NeoTex requires timers support' | echohl None
endif
if !has('nvim') && !has('job')
echohl Error | echomsg 'NeoTex requires neovim or vim 8 with job support' | echohl None
endif
let s:neotex_buffer_tempname = tempname()
if get(g:, 'neotex_latexdiff', 0)
let s:neotex_preview_tempname = tempname()
else
let s:neotex_preview_tempname = s:neotex_buffer_tempname
endif
if !exists('g:neotex_delay')
let g:neotex_delay = 1000
endif
augroup _neotex_
au!
augroup END
command! NeoTexOn au! _neotex_ TextChanged,TextChangedI <buffer> call s:latex_compile_delayed()
command! NeoTexOff au! _neotex_ TextChanged,TextChangedI <buffer>
command! NeoTex call s:latex_compile(0)
command! NeoTexFS call s:zathura_forward_search()
let s:neotex_loaded = 1
endif
let b:neotex_jobexe=''
if get(g:, 'neotex_latexdiff', 0)
let b:neotex_jobexe .= 'latexdiff '
if exists('neotex_latexdiff_options')
let b:neotex_jobexe .= g:neotex_latexdiff_options . ' '
endif
let b:neotex_jobexe .= fnameescape(expand('%:t')) . ' ' . s:neotex_buffer_tempname . ' > ' . s:neotex_preview_tempname . ' && '
endif
let b:neotex_jobexe .= get(g:, 'neotex_pdflatex_alternative', 'pdflatex') . ' -shell-escape -jobname=' . fnameescape(expand('%:t:r')) . ' -interaction=nonstopmode' . ' -synctex=1 '
if exists('neotex_pdflatex_add_options')
let b:neotex_jobexe .= g:neotex_pdflatex_add_options . ' '
endif
let b:neotex_jobexe .= s:neotex_preview_tempname
if get(g:, 'neotex_enabled', 1) == 2
au! _neotex_ TextChanged,TextChangedI <buffer> call s:latex_compile_delayed()
endif
function! s:job_exit(...)
if exists('s:job')
unlet s:job
endif
endfunction
function! s:latex_compile(_)
if exists('s:job')
call s:latex_compile_delayed()
return
endif
call writefile(getline(1, '$'), s:neotex_buffer_tempname)
if has('nvim')
let s:job = jobstart(['bash', '-c', b:neotex_jobexe], {'cwd': expand('%:p:h'), 'on_exit': function('s:job_exit')})
else
let s:job = job_start(['bash', '-c', b:neotex_jobexe], {'cwd': expand('%:p:h'), 'out_io':'null', 'exit_cb': function('s:job_exit')})
endif
if exists('s:timer')
unlet s:timer
endif
endfunction
function! s:latex_compile_delayed()
if exists('s:timer')
call timer_stop(s:timer)
endif
let s:timer = timer_start(g:neotex_delay, function('s:latex_compile'))
endfunction
function! s:zathura_forward_search()
exec "silent !zathura --synctex-forward ".line(".").":".col(".").":".s:neotex_preview_tempname." ".fnameescape(expand('%:p:r')).".pdf &"
endfunction
There is one caveat. Since the tempfile
changes, the function works only if NeoTex has compiled the file in the current session.
I can try to make this implementation if you wish, but I'm totally new to plugins. Let me know if you need something more.
Sorry for bad grammar.
Things work fine when I'm in main.tex. But it issues errors when I move to other tex files, for example, files in sections/ subdirectory. So live preview doesn't work when I'm editing non-main files.
Error detected while processing function <SNR>50_latex_compile:
line 7:
E121: Undefined variable: b:neotex_jobexe
E116: Invalid arguments for function jobstart
E15: Invalid expression: jobstart(['bash', '-c', b:neotex_jobexe], {'cwd': expand('%:p:h'), 'on_exit': function('s:job_exit')})
Could you please clarify how to use latexdiff? I installed your plugin and it works perfectly, exactly what I was looking for, however, I do not see how I can use the diff feature.
Hi,
i installed neotex via a package manager, and upon opening a .tex file i get the error:
Error detected while processing .../tex.vim:
line 20:
E117: Unknown function: _neotex_init
I looked through the code but unfortunately i know nothing about vimscript or how nvim handles the call to python.
Any help would be appreciated, thanks.
// edit: user error :x
Hi there and thanks for creating and maintaining this plugin.
This is more of a feature request and less of an issue. I am hoping that neotex can also support certain TeX directives used in other editors and also vimtex. Here's an example of one of the directives:
% !TEX TS-program = lualatex
On editors / plugins that support this, they will automatically use the specified engine to compile their tex file. This is useful as one may use different engines to render their documents, while neotex currently only allows us to specify one engine. I tried setting the variable g:neotex_pdflatex_alternative
while in a buffer that that did not work.
Here are two links for your reference about these directives: TeX SE and TeXWorks Docs
Supporting these directives will also resolve #8 through % !TeX root
.
It would be great to have an option to compile bibtex references together with the whole document. In essence, a convention that the .bib file should be called the same as the .tex file would be sufficient I think.
As for now I post-compile .aux file with bibtex manually to make the whole thing working.
The general pipeline would be the following (source):
pdflatex <options> doc.tex &&
bibtex doc && # compiles doc.bib
pdflatex && <options> doc.tex
pdflatex <options> doc.tex
Though I think adding it as a permanent pipeline might break the compilation process in case there is no .bib file so it definitely should be an option.
I would try to tuckle the problem myself but I doubt I will succeed in a short term as I'm not a vim-script ninja.
P.S. Sadly, there is no feature-request label to add
Specifically deoplete. Completions don't show up until 5 seconds after typing when g:neotex_delay is set to 5000
Deoplete resumes normal behavior after calling :NeoTexOff
Followed instructions to use vim-plug to install.
The NeoTex command is unavailable.
also have the following in init.vim:
let g:neotex_enabled = 2
Any help appreciated; would really like to get down to editing LaTeX in NeoVim.
How can I make NeoTexOn be on by default?
Maybe this is feature request?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.