batch-filelatexnotepad++ddenppexec

Compiling LaTeX from notepad++ and opening with sumatra. ForwardSearch doesn't work if file path contains umlauts


I've had this small problem for quite some time now and I haven't been able to find a solution even after excessive googling. In this guide it is described how LaTeX can be written and compiled using npp++ and nppExec together with SumatraPDF.

Through some clever scripts and the use of DDE commands (through CMCDDE.exe), it is even possible to use sumatra's ForwardSearch to jump back and forth from the .tex to the .pdf. Everything works great, unless the path to the .tex file contains a character that's not in the English alphabet (for example åäö).

The CMCDDE command then fails because the path sent to sumatra's ForwardSearch reads (for example) C:\†„” instead of C:\åäö. This has to be an encoding issue and I haven't been able to find a working solution.

So, if I have this .tex file C:\åäö\MWE.tex with

\documentclass{article}
\begin{document}
Hello World!
\end{document}

it won't open correctly when using the batch script described in the link above. These are the problematic batch file lines:

::Writes the commands that are to be executed using CMCDDE.exe (through cmcdde.tmp)
echo SUMATRA>"%~dp1build\cmcdde.tmp"
::%~dp1build transforms into C:\åäö\build for the MWE
echo control>>"%~dp1build\cmcdde.tmp"
echo [ForwardSearch("%~dp1build\%~n1.pdf", "%~f1", %2, 0, 0, 0)]>>"%~dp1build\cmcdde.tmp" 
:: This gives the following line in cmcdde.tmp: [ForwardSearch("P:\Documents\†„”\build\MWE.pdf", "P:\Documents\†„”\MWE.tex", 3, 0, 0, 0)] (in ANSI encoding)

"P:\Documents\localtexmf\cmcdde.exe" @"%~dp1build\cmcdde.txt"
:: This fails because the path P:\Documents\†„”\build doesn't exist (P:\Documents\åäö\build does)

Ideas I've had and tried:

Please let me know if something which parts of the question that are unclear.


Solution

  • I managed to find a solution. Turns out using the code page 1252 solves the problem.

    So putting chcp 1252 at the beginning of the batch file is the solution. However, if you're using other none standard characters than me (other then the ones in the nordic alphabet), I'm guessing you might need another code page.

    Experiment and test different ones until you get it working.