[Tex/LaTex] compiling pdflatex from the terminal in vim

texliveUbuntuvim

A file I can compile in Texmaker won't compile after editing in Vim. I am giving the error hw9problem1xplot can't be found. This is from an includegraphics command. However, the pdf image file is in the same folder as the tex file, and I was able to compile this file with the includegraphics from Texmaker.

What I have been doing is :w and :!pdflatex % but I am told that the pdf image file doesn't exist or it can't find it. How can this be? I can compile the file in Texmaker without an issue.

So I found the problem, Vim is saving the file elsewhere and not where I pulled the file from. So it is looking for the pdf in the wrong directory. How can I change where Vim saves the file?

What do I need to setup to correct this issue?

After vonbrand's a suggestion, I tried running :!pdflatex -shell-escape %. Unfortunately, I received the same error message.

! LaTeX Error: File `hw9problem1xplot' not found.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...                                              

l.86 ...degraphics[width = 3in]{hw9problem1xplot}}

I have tried hw9problem1xplot with and without .pdf too.

I commented out the figure with the with the includegraphics and it compiled without an issue. I double checked the folder and the pdfs are present so I don't know what the problem is.

Best Answer

Vim was saving to the home directory when I was working with a file in documents.

So I changed the the working directory to my documents by:

:cd %:p:h
Related Question