# Specifying the destination for the pdf output when using pdflatex, from gVim

I am generating a pdf output with `pdflatex` with the following command in gVim:

``````:!pdflatex %
``````

This command in turns executes the following in the Command Prompt:

``````cmd.exe /c pdflatex /testvim.tex
``````

Now, the problem I'm having with this is that the pdf is outputted to the `system32` folder:

``````C:\windows\system32\testvim.pdf
``````

How can I instruct `pdflatex` to generate the pdf in the folder where the `tex` file resides?

-

## 1 Answer

Apparently you can use

``````-output-directory <wherever>
``````

To get the directory of the current file, you'll need to use:

``````expand('%:h')
``````

but you'll need to write a macro or a function that can evaluate that; something like:

``````map ,,p :exe "!pdflatex -output-directory " . expand('%:h') . " %"<CR>
``````
-