Forum moved here!

Home / [How-To] Part1 - Using CLI & DDE with SumatraPDF

GitHubRulesOK

The next text item is separated such that it can be updated like a “sticky” at the top of page

Part1 is general (not specific to (La)TeX) so you may find a useful command tip or two

please click like if it helps you and feel free to critique so I may be encouraged to correct or
update it. If you wish to download the referenced Fig1.PNG and Fig2.PNG
here they are (right click to save as)

Fig1.PNG

Fig2.PNG Notepad++ creating PDF for SumatraPDF

GitHubRulesOK

:< html>< body>
@call “%~dp0Fig1.png” & call “%~dp0Fig2.png” & more +2 “%~f0” & pause & goto end & :BEGIN

: Release 18.01.04.05 by KJDO - Copyleft per SumatraPDF (A)GPLv3
: Hypertext or MetaTeXt ( https://en.wikipedia.org/wiki/Hypertext_(semiotics) )
: Source uploaded as html but will be displayed as text. To restore it change
: the first line to :< html>< body>< code> without any spaces
: also edit (replace) ALL QUOTES to standard double quotes (usually shifted 2)
: see [How-To] Part1 - Using CLI & DDE with SumatraPDF

Help notes for SumatraPDF (& Portable) using CLI or DDE calls

CLI (command line interface) is the root means of calling the core DOS commands.
These notes are written in the same style as I’ve been using since pre Windows.

DDE (Dynamic Data Exchange) is part of core Windows, simply double click this
.txt file & Windows uses DDE-execute to [OPEN(“ThisFile”)] in Notepad / Wordpad
or your default editor (see more about DDE Forward or Inverse Search later).

This help file may be saved as “any-name.cmd” (or .bat) e.g. CLI-DDE-help.cmd.
Then when you double click it to run, these contents will show in a DOS window,
and if Fig1.PNG is in the same directory it opens in your default image viewer,
WITHOUT invoking DDEexec as such, though DDE will probably have been part used.

The following is a basic discourse on using CLI / DDE interaction and SumatraPDF

IF you are reading this in SumatraPDF as .PDF or .txt (which requires
ADVANCED settings > EbookUI [
UseFixedPageUI = true
]
THEN be aware MOST HYPER-LINKS WILL BE ACTIVE and can lead your browser to web
pages I’ve NO control over, PROCEED WITH CAUTION ! IF in doubt don’t click them.

for fuller command examples see
https://www.sumatrapdfreader.org/docs/Command-line-arguments.html
and
https://www.sumatrapdfreader.org/docs/DDE-Commands.html

IF .PDF is a registered file-class AND SumatraPDF is the default Application

THEN the simplest way to control SumatraPDF is to
	DDE open a document with a page number
	SO to open a PDF 400 pixels down on page 2 you could use a cmd

or short-cut to START “E:\sample.pdf” -page 2 -scroll 0,400

ELSE

IF .PDF is NOT a registered class then the above DDE-exec [Open("%1" %*] will
NOT work, you may get error messages or another app / command window may start.

THUS double clicking etc. is NOT SO GOOD FOR PORTABLE USAGE

THEN you need to START SumatraPDF.EXE with CLI file-name [commands]

A typical portable CLI (command line interface) command (or short-cut) could be

“F:\PortableApps\SumatraPDFPortable\SumatraPDFPortable.exe” ^
“E:\sample.pdf” -named-dest “Table of Contents”

NOTE ^ is used on first line in a batch file to append two lines as if one

OR

START “” F:\PortableApps\SumatraPDFPortable\SumatraPDFPortable.exe ^
“E:\sample.pdf” -page 2 -scroll 0,400

These CLI (command line interface) instructions are usually good enough for most
user short-cut or .BATch / .ComManD files and can be combined fairly powerfully
for macro control by using -reuse-instance, SO why bother calling DDE control ?

The above CLI commands can be called directly from other programs using DDE and
most DDE calls have a CLI equivalent, even forward / inverse search, HOWEVER
many “.TeX” authoring tools prefer to use DDE in the background to quickly jump
backwards and forwards between given lines. This is a common function within the
TeXworks Editor & its SyncTeX PDF viewer BOTH included in NOOB (New Out OF Box)
MiKTeX Portable. see Fig 1.

It is only when TeXworks front end and its back end PDF viewer are replaced by
Notepad++ or WinEdt 10 or any other heavy-weight front end editors and combined
with Acrobat or Foxit or SumatraPDF viewers to create a TeX authoring Suite that
the SyncTeX links need to use direct DDE execute control.

To see more help on this go to https://www.sumatrapdfreader.org/docs/Use-Sumatra-as-a-pre-viewer-for-LaTeX-editors-06174d1d7be24e10966656261c70ed7f.html

NOTE for DDE commands to work SumatraPDF MUST either be active as a service
application (thus the -reuse-instance command) OR needs to be started first

NOTE since windows Vista onwards, DDE security has been modified to tighten
UAC (User Account Control) in some cases blocking full DDE interaction and
these CLI / DDE utilities may be upset or affect your implied security level.

For the examples above you would need to first

START "F:\PortableApps\SumatraPDFPortable\SumatraPDFPortable.exe"
OR using DDE-execute with the correct syntax invoke along the lines of
Server: SUMATRA Topic: control Command: “[Open(“E:\sample.pdf”,0,1,1)]”

Then further DDE “triplets” would be

SUMATRA|control|"[GotoNamedDest(“E:\sample.pdf”,“Table of Contents”)]"

or

SUMATRA|control|"[GotoPage(“E:\sample.pdf”,2)]“
and
SUMATRA|control|”[SetView(“E:\sample.pdf”,“continuous”,-3,0,400)]

OK enough of the theory, how to see this in practice ?

TWO FINAL WARNINGS
I repeat the following links are beyond my control
and since windows Vista onwards, DDE security has been modified to tighten
UAC (User Account Control) blocking full DDE interaction between user and admin
apps thus these CLI utilities may upset or affect your implied security level,
but you know the risk since you will be using portable apps !

there are several CLI DDE Executables available such as

XMPlay Controller, established 1998 an early example of how easy it may be done
but NOT for SumatraPDF see http://support.xmplay.com/files_view.php?file_id=628

DDE Command (a.k.a. ddecmd) v1.6 = 23/04/2017 by Chris Oldwood, very useful
but perhaps more powerful than needed, see http://www.chrisoldwood.com/win32.htm

cl-2-dde (command-line-version-dde-client) c 2012 by Andrej Kulikov, specially
crafted for SumatraPDF & Notepad++ this is the one we will modify for portable
use later see http://code.google.com/p/command-line-version-dde-client
download = https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/command-line-version-dde-client/cl-2-dde-1.0.zip

Consider

CavePerson > Brain > Hand > Charcoal > Wall > Drawing > Archaeologist

now consider the more modern process

Author > Computer > GUI > Input > Compiler > SynchronizedOutput > Reader

Not exactly analogical but the intended conveyance of concepts is the same plus
you have the bonus of jumping back to change the source (approx. = Time Travel)

Author = You
GUI (Graphics User Interface) = Your choice of front end editor e.g. Notepad++
Input = A file such as a .(la)TeX document
Compiler = TeX to DVI or PDF Subsystem such as MiKTeX
Synchronised Output = The DVI or PDF [with .SyncTeX or .pdfTeX file]
Reader = Your user with application such as SumatraPDF that can DDE back to GUI

Since many Windows TeX systems advise or require MiKTeX let us download
(currently MiKTeX-portable-2.9.6521.exe) from https://miktex.org/portable

Install by default to a USB drive (Be aware most installations can be over a GB)

To see Forward and Reverse (Inverse) search in action, run MiKTeX-portable.cmd
right click the tray icon and at top of menu select TeXworks. Download and open
standard file from ftp://www.ctan.org/tex-archive/macros/latex/base/small2e.tex

Keep the default of pdfLaTeX+MakeIndex+BibTeX then either select Typeset, Ctrl-T
or simply click on the green go button. The right hand screen should be the PDF
version, right click anywhere to see “Jump to …” allowing you to jump forward
from .TeX file or inversely back from .PDF file to the opposing text character.

NOTE we did not have to configure DDE its all done automagically using SyncPDF

Now the first steps testing how SumatraPDF behaves with the SyncPDF files

IF you have problems beware the following changes for each use of quotes
and ALL pairs of quotes should be standard double quotes (this page will
likely have corrupted them when you cut and paste)

you need to edit the following lines as appropriate keep the ^
since it appends each following line

First we need to open Sumatra so it starts a DDE Channel,We can at the same
time give it a file to open and a line to highlight. Line numbers are not what
you see in the PDF they are per the source

see Fig2.PNG where Notepad++ asks for 14 and SumatraPDF Highlights Line 2 and 3

: TIP to find source line number in SumatraPDF change inverse command to
: notepad %f %l (yes thats an L)
: double click line and notepad will say can not find source.ltx ## file

MOST IMPORTANT the .SyncTeX file is expected to be in the same directory
as the .pdf whereas most editors usually build it in the source directory

The following works if small2e.synctex or small2e.synctex.gz are in
F:\LaTeX\OutPut\ not F:\LaTeX\Source\

you need a copy of “Aux” files, so uncheck any delete commands in the editor

NOTE AT THIS POINT WE ARE STILL USING CLI CALLS NOT DDE, AS SUCH (yet)

edit a separate batch file e.g. FORWARD.BAT with the next half a dozen lines changed to suite your file locations

“F:\MyApps\SumatraPDF\SumatraPDF-3.1.2\rel\SumatraPDF-portable.exe” ^
-reuse-instance “F:\LaTeX\OutPut\HelloWorld.pdf” ^
-forward-search “F:\LaTeX\Source\HelloWorld.tex” 14
REM wait 5 seconds to allow user to see any error messages
: (for XP without timeout command use PING localhost -n 6 >NUL)
timeout /T 5 >nul

More on configuring SumatraPDF as a viewer with LaTeX editors in Part 2

@:END