summaryrefslogtreecommitdiff
path: root/obsolete/info/MiKTeX+Ghostscript+GSview+USB-drive-HOWTO.txt
blob: 0c7e7104f8b8813d0181816cf324541a1c349ae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
MiKTeX+Ghostscript+GSview+USB-drive-HOWTO.txt

Alexander Grahn

Version 1.06, 2nd May 2007

Copyright © 2006 Alexander Grahn

This HOWTO provides instructions for setting up a portable installation
of MiKTeX (>=2.5), Ghostscript and GSview on external storage devices,
such as USB sticks or mapped network drives, for use with MS Windows
(2000, 2003, XP, ...)  computers.

Permission is granted to copy, distribute and/or modify this HOWTO
under the terms of the GNU Free Documentation License (GFDL), Version
1.1 or any later version published by the Free Software Foundation. See
http://www.fsf.org for details of this license. This HOWTO is distributed
in the hope that it will be useful, but WITHOUT ANY WARRANTY.

-----------------------------------------------------------------------------

1 Introduction
==============

A portable TeX/LaTeX/PS-viewer installation for MS Windows can be
easily created by copying existing installations of MiKTeX, Ghostscript
and GSview to a USB storage device and adding some helper scripts
for initialization and utilizing the software. In fact, the procedure
described here is not restricted to USB drives but works with everything,
which, apart from being writable, has a leading drive letter, such as
"E:", in its path, e. g. mapped network drives.

As Ghostscript (together with the PS fonts directory) and GSview are
quite small (they consume less than 30 MB), the required size of the USB
drive mainly depends on the number of packages that have been or will
be installed with the MiKTeX system. The MiKTeX Package Manager which
ships with the MiKTeX system allows to update or extend the portable
installation at any time the USB drive is plugged into a Windows box
with internet connection. A script for starting the Package Manager is
provided within this document.

The initialization of the portable installation involves some manipulation
of the Windows Registry in order to associate file name extensions
(.dvi, .ps, .eps) with the appropriate programs (Yap, GSview) of the
installation. These changes only affect the current user's settings
branch (HKEY_CURRENT_USER) of the Registry. Therefore, no additional
administrative rights are necessary to run the initialization script
and to use the software. Existing application settings as well as file
type associations are backed up and should be restored after finishing
the session using another script given in this document.

The installation of other software which might complete the portable
system, such as text editors, additional viewers, drawing programs etc. is
not covered here as it depends largely on personal requirements and taste.


2 Prerequisites
===============

First of all, we need working installations of Ghostscript, GSview
and MiKTeX on some Windows box. At the beginning, a small installation
(private or shared) of MiKTeX will do, since it can be extended later
using the Package Manager.

Create two empty folders `texmf' and `localtexmf' somewhere on your USB
drive.  The root directory of the drive is probably the best place for
both folders to go to, although any number of intermediate directories
is acceptable. For the portable installation to work it is necessary
that the files which follow in this document be put to the same parent
directory as the `texmf' and `localtexmf' folders.

Now we are going to copy the original MiKTeX installation, which could
reside, say, in `C:\Program Files\MiKTeX 2.5', to the USB drive. Copy
everything you find in this folder (but not the folder itself!) into
the `texmf' directory on your USB drive. The `texmf' directory tree is
the one that will be maintained by the Package Manager and the Update
Wizzard. The `localtexmf' tree is the place where TeXperts will put
their own or third party packages.

Copy the `gs' folder (containing the `fonts' directory) of a Ghostscript
installation and the `Ghostgum' folder of a GSview installation to the
same parent directory which already contains the `texmf' and `localtexmf'
folders.

The next thing we need is the `reg.exe' utility, version 3.0, such that
we can manipulate the Windows Registry from within our scripts. It
resides in the system directory (c:\WINDOWS\system32) of Windows XP
or 2003 computers. However, there is no `reg.exe' on Windows 2000
computers. Make a copy of `reg.exe' to the parent directory of your
portable installation. It is a good idea to have it there in case you
want to plug your USB stick to a Windows 2000 computer.


3 Adding the scripts
====================

Now add all the DOS batch (.bat) scripts you find at the end of this
document to the same parent directory which contains the other folders
we have copied so far. With the exception of `versions.bat' none of
the scripts needs any modification.

`versions.bat', which is not intended to be run directly, is called by
some of the remaining scripts. It sets three script variables to the
version numbers of MiKTeX, Ghostscript and GSview. Edit this file and
make sure that the numbers therein match the actual program versions
of your installation. Line breaks must follow immediately after the
numbers. Spaces around them are not allowed.

########################################################################
*NB*: The `MIKTEX_VERSION', `GS_VERSION' and `GSVIEW_VERSION' variables
      which are set in the file `versions.bat' need to be adjusted
      according to the program versions being in use.
########################################################################

Don't forget to edit `versions.bat' whenever you update MiKTeX,
Ghostscript and/or GSview to a different version!

The purpose of each script is listed in the following.

versions.bat  Called by `init.bat', `reset.bat' and `cmd.bat'. Sets the
              `MIKTEX_VERSION', `GS_VERSION' and `GSVIEW_VERSION'
              variables.

init.bat      Initialises the MiKTeX, Ghostscript and GSview installations
              on the USB drive. Associates the .dvi file name extension
              with Yap and the .ps/.eps extensions with GSview. Backups
              current user's file associations and application settings
              of possibly existing MiKTeX and GSview installations on the
              host computer and loads settings of the previous portable
              session instead. Creates a context menu item for files and
              folders, which allows to open a DOS command line prompt for
              TeXifying documents at the location of a file or folder by
              right click.

reset.bat     To be run after finishing a session and before disconnecting
              the USB or network drive. Restores previous file associations
              and application settings. Saves the settings of the portable
              session to the USB drive.

mpm.bat       Starts the MiKTeX Package Manager for installation of
              additional packages. The Update Wizzard can be started from
              within the package manager via the `Task' menu.

mo.bat        Starts the MiKTeX Options setting tool.

yap.bat       Yet another means to open Yap. Drag and drop a .dvi file on
              `yap.bat'.

gsview.bat    Yet another means to open GSview. Drag and drop a Postscript
              file on `gsview.bat'.

cmd.bat       Yet another means to open a DOS command line window. Drag and
              drop a file or directory on `cmd.bat' to open the command
              line at the location of the file/directory.

The final directory structure should be as follows:

<drive letter>:[<\intermediate\directories>]\texmf\
<drive letter>:[<\intermediate\directories>]\localtexmf\
<drive letter>:[<\intermediate\directories>]\gs\
<drive letter>:[<\intermediate\directories>]\Ghostgum\
<drive letter>:[<\intermediate\directories>]\reg.exe
<drive letter>:[<\intermediate\directories>]\versions.bat
<drive letter>:[<\intermediate\directories>]\init.bat
<drive letter>:[<\intermediate\directories>]\reset.bat
<drive letter>:[<\intermediate\directories>]\mpm.bat
<drive letter>:[<\intermediate\directories>]\mo.bat
<drive letter>:[<\intermediate\directories>]\yap.bat
<drive letter>:[<\intermediate\directories>]\gsview.bat
<drive letter>:[<\intermediate\directories>]\cmd.bat


4 Using the portable installation
=================================

After connecting the USB drive to a Windows computer, the initialization
process is started by double click on `init.bat'. A DOS window opens,
displaying the output of the `initexmf' program run by the script.
Please wait until you are asked to hit a key for closing the window.

Once the DOS window is closed, the portable MiKTeX/Ghostscript/GSview
installation is ready for use. The most comfortable way to TeXify a
document is to open a DOS command line at its location: Right click
on a folder or file and select "Command Prompt Here" from the context
menu. Alternatively, you can drag and drop a folder or file onto
the `cmd.bat' icon. At the command line you will have access to all
executables (latex, pdflatex, bibtex, dvips, ps2pdf, ...) necessary to
process your documents. The resulting .dvi and .ps files can easily be
opened by double click, since appropriate file associations have been
established during initialization.

Before disconnecting the USB drive, it is a good idea to run `reset.bat'
in order to undo the changes which have been made to the Registry and to
restore personal application settings which were in effect before the
session. This ensures to wipe out any traces of your portable session
and to avoid possible interferences with existing MiKTeX/GS/GSview
installations on the host computer.


5 DOS batch scripts
===================

5.1 versions.bat
=================
--8<----------------------------------------------------------------------
rem MiKTeX
set MIKTEX_VERSION=2.5

rem Ghostscript
set GS_VERSION=8.56

rem GSview
set GSVIEW_VERSION=4.8
-->8----------------------------------------------------------------------


5.2 init.bat
============
--8<----------------------------------------------------------------------
@echo off

rem set path
set path=%~dp0texmf\miktex\bin;%path%

rem test whether a lock entry exists in the Registry
reg query HKCU\Software\TeX-portable 2>nul 1>nul && (
  echo `%~nx0' can be run only once per session, run `reset.bat' first!
  echo.
  pause
  exit
)

cls
echo Please wait...

rem set version numbers
call "%~dp0versions.bat"

rem add lock entry to the Registry
reg add HKCU\Software\TeX-portable /f 2>nul 1>nul

rem create folder context menu item for opening a DOS command line
reg add "HKCU\Software\Classes\Folder\shell\ZCmdHere" /ve /t REG_SZ /d "Command Prompt Here" /f 1>nul 2>nul
reg add "HKCU\Software\Classes\Folder\shell\ZCmdHere\command" /ve /t REG_SZ /d "\"%~dp0cmd.bat\" \"%%1\"" /f 1>nul 2>nul

rem create file context menu item for opening a DOS command line
reg add "HKCU\Software\Classes\*\shell\ZCmdHere" /ve /t REG_SZ /d "Command Prompt Here" /f 1>nul 2>nul
reg add "HKCU\Software\Classes\*\shell\ZCmdHere\command" /ve /t REG_SZ /d "\"%~dp0cmd.bat\" \"%%1\"" /f 1>nul 2>nul

rem backup existing .dvi entry
reg query HKCU\Software\Classes\.dvi 2>nul 1>nul && (
  reg copy HKCU\Software\Classes\.dvi HKCU\Software\Classes\.dvi.bak /f /s 2>nul 1>nul
)

rem create new (private) file association for .dvi
reg add HKCU\Software\Classes\.dvi /ve /d "my_dvifile" /f 2>nul 1>nul
reg add HKCU\Software\Classes\my_dvifile\shell\open\command /ve /d "\"%~dp0texmf\miktex\bin\yap.exe\" \"%%1\"" /f 2>nul 1>nul
reg add HKCU\Software\Classes\my_dvifile\DefaultIcon /ve /d "\"%~dp0texmf\miktex\bin\yap.exe\"" /f 2>nul 1>nul

rem backup existing .ps/.eps entries
reg query HKCU\Software\Classes\.ps 1>nul 2>nul && (
  reg copy HKCU\Software\Classes\.ps HKCU\Software\Classes\.ps.bak /s /f 2>nul 1>nul
)
reg query HKCU\Software\Classes\.eps 1>nul 2>nul && (
  reg copy HKCU\Software\Classes\.eps HKCU\Software\Classes\.eps.bak /s /f 2>nul 1>nul
)

rem create new (private) file associations for .ps/.eps
reg add HKCU\Software\Classes\.ps /ve /d "my_psfile" /f 2>nul 1>nul
reg add HKCU\Software\Classes\.eps /ve /d "my_psfile" /f 2>nul 1>nul
reg add HKCU\Software\Classes\my_psfile\shell\open\command /ve /d "\"%~dp0Ghostgum\gsview\gsview32.exe\" \"%%1\"" /f 2>nul 1>nul
reg add HKCU\Software\Classes\my_psfile\DefaultIcon /ve /d "\"%~dp0Ghostgum\gsview\gsview32.ico\"" /f 2>nul 1>nul

rem backup existing gsview32.ini file in the %USERPROFILE% directory
if exist "%USERPROFILE%\gsview32.ini" (
  del "%USERPROFILE%\gsview32.ini.bak" 1>nul 2>nul
  ren "%USERPROFILE%\gsview32.ini" gsview32.ini.bak 1>nul 2>nul
)

rem write gsview32.ini file on USB drive
echo [GSview-%GSVIEW_VERSION%]> "%~dp0Ghostgum\gsview\gsview32.ini"
echo Configured=1 >> "%~dp0Ghostgum\gsview\gsview32.ini"
echo Version=%GSVIEW_VERSION%>> "%~dp0Ghostgum\gsview\gsview32.ini"
echo GhostscriptDLL=%~dp0gs\gs%GS_VERSION%\bin\gsdll32.dll>> "%~dp0Ghostgum\gsview\gsview32.ini"
echo GhostscriptEXE=%~dp0gs\gs%GS_VERSION%\bin\gswin32c.exe>> "%~dp0Ghostgum\gsview\gsview32.ini"
echo GhostscriptInclude=%~dp0gs\gs%GS_VERSION%\lib;%~dp0gs\fonts;%~dp0gs\gs%GS_VERSION%\Resource>> "%~dp0Ghostgum\gsview\gsview32.ini"
echo GhostscriptOther=-dNOPLATFONTS -sFONTPATH="c:\psfonts">> "%~dp0Ghostgum\gsview\gsview32.ini"
echo. >> "%~dp0Ghostgum\gsview\gsview32.ini"

rem append GSview settings from last session
if exist "%~dp0.gsview32.ini" (
  type "%~dp0.gsview32.ini" >> "%~dp0Ghostgum\gsview\gsview32.ini"
)

rem backup existing MiKTeX settings for later restore
reg query HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% 1>nul 2>nul && (
  reg copy HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%.bak /s /f 1>nul 2>nul
  reg delete HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% /f 1>nul 2>nul
)
reg query HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% 1>nul 2>nul && (
  reg copy HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%.bak /s /f 1>nul 2>nul
  reg delete HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% /f 1>nul 2>nul
)

rem load MiKTeX settings from previous session
if exist "%~dp0.MiKTeX.reg" (
  reg import "%~dp0.MiKTeX.reg" 1>nul 2>nul
)

rem on startup, don't let Yap check whether it is the default viewer (this breaks the .dvi file association)
reg add HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%\Yap\Settings /v "Check Associations" /d 0 /t REG_DWORD /f 1>nul 2>nul

rem initialize MiKTeX
reg add HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%\Core /v "Install" /d "%~dp0texmf" /t REG_SZ /f 1>nul 2>nul
reg add HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%\Core /v "Roots" /d "%~dp0localtexmf;%~dp0texmf" /t REG_SZ /f 1>nul 2>nul
reg add HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%\Core /v "UserData" /d "%~dp0.userdata" /t REG_SZ /f 1>nul 2>nul
reg add HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%\Core /v "UserConfig" /d "%~dp0.userconfig" /t REG_SZ /f 1>nul 2>nul
initexmf.exe --verbose --dump --mklinks
initexmf.exe --verbose --mkmaps
initexmf.exe --verbose --update-fndb

cls
echo.
echo The portable MiKTeX/GS/GSview installation is now ready for use!
echo.
echo *********************************************************************
echo ** IMPORTANT: Don't forget to run `reset.bat' before disconnecting **
echo **            the USB drive!                                       **
echo *********************************************************************
echo.
pause
-->8----------------------------------------------------------------------

5.3 reset.bat
=============
--8<----------------------------------------------------------------------
@echo off

set path=%~dp0Ghostgum\gsview;%path%

rem test whether a lock entry exists in the Registry
reg query HKCU\Software\TeX-portable 2>nul 1>nul || (
  echo There is nothing to be reset. Aborting...
  echo.
  pause
  exit
)

echo.
echo **********************************************************************
echo ** IMPORTANT: Make sure that all instances of Yap have been closed! **
echo **            GSview will close automatically.                      **
echo **********************************************************************
echo.
pause

rem close all instances of GSview
gsview32 -x

cls
echo Please wait...

rem set version numbers
call "%~dp0versions.bat"

rem restore previous file associations
reg delete HKCU\Software\Classes\.dvi /f 2>nul 1>nul
reg query HKCU\Software\Classes\.dvi.bak 1>nul 2>nul && (
  reg copy HKCU\Software\Classes\.dvi.bak HKCU\Software\Classes\.dvi /s /f 2>nul 1>nul
  reg delete HKCU\Software\Classes\.dvi.bak /f 2>nul 1>nul
)

reg delete HKCU\Software\Classes\.ps /f 2>nul 1>nul
reg query HKCU\Software\Classes\.ps.bak 1>nul 2>nul && (
  reg copy HKCU\Software\Classes\.ps.bak HKCU\Software\Classes\.ps /s /f 2>nul 1>nul
  reg delete HKCU\Software\Classes\.ps.bak /f 2>nul 1>nul
)

reg delete HKCU\Software\Classes\.eps /f 2>nul 1>nul
reg query HKCU\Software\Classes\.eps.bak 1>nul 2>nul && (
  reg copy HKCU\Software\Classes\.eps.bak HKCU\Software\Classes\.eps /s /f 2>nul 1>nul
  reg delete HKCU\Software\Classes\.eps.bak /f 2>nul 1>nul
)

reg delete HKCU\Software\Classes\my_dvifile /f 2>nul 1>nul
reg delete HKCU\Software\Classes\my_psfile /f 2>nul 1>nul

rem dump current MiKTeX settings to `.MiKTeX.reg' on the USB drive
reg query HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% 1>nul 2>nul && (
  reg export HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% "%~dp0.MiKTeX.reg" 1>nul 2>nul
)

rem restore previous MiKTeX settings
reg delete HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% /f 1>nul 2>nul
reg query HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%.bak 1>nul 2>nul && (
  reg copy HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%.bak HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% /s /f 1>nul 2>nul
  reg delete HKCU\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%.bak /f 1>nul 2>nul
)
reg query HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%.bak 1>nul 2>nul && (
  reg query HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% 1>nul 2>nul && (
    reg delete HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% /f 1>nul 2>nul
  )
  reg copy HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%.bak HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION% /s /f 1>nul 2>nul
  reg delete HKLM\Software\MiKTeX.org\MiKTeX\%MIKTEX_VERSION%.bak /f 1>nul 2>nul
)

rem copy current GSview settings to USB drive
if exist "%USERPROFILE%\gsview32.ini" (
  copy "%USERPROFILE%\gsview32.ini" "%~dp0.gsview32.ini" 1>nul 2>nul
  del "%USERPROFILE%\gsview32.ini" 1>nul 2>nul
)

rem restore backup version of gswin32.ini
if exist "%USERPROFILE%\gsview32.ini.bak" (
  ren "%USERPROFILE%\gsview32.ini.bak" gsview32.ini
)

rem delete folder and file context menu item
reg delete HKCU\Software\Classes\Folder\shell\ZCmdHere /f 1>nul 2>nul
reg delete HKCU\Software\Classes\*\shell\ZCmdHere /f 1>nul 2>nul

rem delete lock entry in the Registry
reg delete HKCU\Software\TeX-portable /f 2>nul 1>nul

cls
echo You can now disconnect the USB drive!
echo.
pause
-->8----------------------------------------------------------------------

5.4 mpm.bat
===========
--8<----------------------------------------------------------------------
@echo off
set path=%~dp0texmf\miktex\bin;%path%
start mpm.exe
-->8----------------------------------------------------------------------

5.5 mo.bat
===========
--8<----------------------------------------------------------------------
@echo off
set path=%~dp0texmf\miktex\bin;%path%
start mo.exe
-->8----------------------------------------------------------------------

5.6 yap.bat
===========
--8<----------------------------------------------------------------------
@echo off
set path=%~dp0texmf\miktex\bin;%path%
start yap.exe %*
-->8----------------------------------------------------------------------

5.7 gsview.bat
==============
--8<----------------------------------------------------------------------
@echo off
set path=%~dp0Ghostgum\gsview;%path%
start gsview32.exe %*
-->8----------------------------------------------------------------------

5.8 cmd.bat
===========
--8<----------------------------------------------------------------------
@echo off

rem set version numbers
call "%~dp0versions.bat"

rem set path to executables
set path=%~dp0gs\gs%GS_VERSION%\lib;%~dp0gs\gs%GS_VERSION%\bin;%~dp0texmf\miktex\bin;%path%

rem MiKTeX environment
if not exist texmf\nul (
  rem extra paths to locate .bib files.
  set BIBINPUTS=.//
  rem Extra paths to locate .bst files.
  set BSTINPUTS=.//
  rem Extra paths to locate METAFONT input and openin files.
  set MFINPUTS=.//
  rem Extra paths to locate MetaPost input files.
  set MPINPUTS=.//
  rem Extra paths to locate TeX \input and \openin files.
  set TEXINPUTS=.//
)

rem Ghostscript environment
set GS_DLL=%~dp0gs\gs%GS_VERSION%\bin\gsdll32.dll
set GS_LIB=%~dp0gs\gs%GS_VERSION%\lib;%~dp0gs\fonts;%~dp0gs\gs%GS_VERSION%\Resource

rem chdir to the first argument or, if it's a file, to its parent dir
(
  %~d1
  cd %1 || cd "%~p1"
) 1>nul 2>nul

rem open console
cmd.exe
-->8----------------------------------------------------------------------