1

I have a latex file which includes multiple figures. These figures are kept in different directories whose path is given in the latex file using the graphicx package:

\usepackage{graphicx} 

\graphicspath{{./path1/}{./path2/}}

I am able to compile this file without any problems from the command prompt using pdflatex file.tex.

Now I have defined a key mapping in my vimrc file:

map <F10> :!pdflatex % <CR>

so that I can compile the file from the vim itself. But in this case, pdflatex is unable to find the figure files.

Can someone please help me understand why pdflatex is able to run without any problem from the command line but runs into problems when run using a key mapping.

Thank you.

3
  • There's nothing on the left hand side of your mapping. What input is supposed to trigger :!pdflatext ... ?
    – B Layer
    Feb 14 at 15:43
  • I have corrected the post. Thanks.
    – Salil
    Feb 14 at 16:06
  • 1
    Check :pwd maybe?
    – D. Ben Knoble
    Feb 14 at 21:15
1

As suggested by @D.BenKnoble, checking :pwd revealed that the current directory was set to my home directory.

I have now set it to my working directory and it works.

One can set the current directory to the directory of the file being edited (see https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file) by including the following command in vimrc:

set autochdir

Or as a one-off, by using the following command:

:lcd %:p:h

Here % gives the name of the current file, %:p gives its full path, and %:p:h gives its directory

2
  • 1
    This answer also appeared in the first post review queue I think it's fine to use that as an answer but maybe it would be useful for future readers to show how you set up the working directory.
    – statox
    Feb 15 at 12:55
  • @Salil Can you please expand on why your current directory was being set to the home directory and what you changed to rectify the situation? Please edit the question with an update.
    – filbranden
    Feb 15 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.