4 Handling of LaTeX distributions
7 # This script contains the following functions:
9 # - LaTeXActions (checks if MiKTeX or TeXLive is installed)
11 # - InstallMiKTeX (installs MiKTeX if not already installed),
12 # only for bunlde installer, uses:
13 # LaTeXCheck # function from LyXUtils.nsh
16 # (installs the LaTeX class files that are delivered with LyX,
17 # a Perl interpreter for splitindex
18 # and enable MiKTeX's automatic package installation)
21 # (installs the LaTeX class files that are delivered with LyX)
23 # - UpdateMiKTeX (asks to update MiKTeX)
25 # ---------------------------------------
28 # checks if MiKTeX or TeXLive is installed
30 StrCpy $Is64bit "false"
33 SetRegView 64 # the PATH is in the 64bit registry section
35 # test if MiKTeX is installed
36 # reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
37 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
38 StrCpy $Search "miktex"
39 Call LaTeXCheck # sets the path to the latex.exe to $PathLaTeX # Function from LyXUtils.nsh
41 StrCpy $String $PathLaTeX
42 StrCpy $Search "x64" # search if it is 64bit MiKTeX
43 Call StrPoint # Function from LyXUtils.nsh
44 ${if} $Pointer != "-1" # if something was found
45 StrCpy $Is64bit "true"
48 # check for 32bit MiKTeX
49 ${if} $PathLaTeX != ""
50 ${andif} $Is64bit != "true"
54 # check if MiKTeX 2.8 or newer is installed
57 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
63 ${if} $String == "2.8"
64 StrCpy $MiKTeXVersion "2.8"
65 StrCpy $LaTeXName "MiKTeX 2.8"
67 ${if} $String == "2.9"
68 StrCpy $MiKTeXVersion "2.9"
69 StrCpy $LaTeXName "MiKTeX 2.9"
73 # check for 64bit MiKTeX
74 ${if} $LaTeXName == ""
78 # check if MiKTeX 2.8 or newer is installed
81 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
87 ${if} $String == "2.8"
88 StrCpy $MiKTeXVersion "2.8"
89 StrCpy $LaTeXName "MiKTeX 2.8"
91 ${if} $String == "2.9"
92 StrCpy $MiKTeXVersion "2.9"
93 StrCpy $LaTeXName "MiKTeX 2.9"
97 ${if} $PathLaTeX != ""
98 StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
99 ${else} # check if MiKTeX is installed only for the current user
101 SetRegView 64 # the PATH is in the 64bit registry section
103 ReadRegStr $String HKCU "Environment" "Path"
104 StrCpy $Search "miktex"
105 Call LaTeXCheck # function from LyXUtils.nsh
106 ${if} $PathLaTeX != ""
107 StrCpy $MiKTeXUser "HKCU"
110 ${if} $LaTeXName == "" # check for the MiKTeX version
113 EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
119 ${if} $String == "2.8"
120 StrCpy $MiKTeXVersion "2.8"
121 StrCpy $LaTeXName "MiKTeX 2.8"
123 ${if} $String == "2.9"
124 StrCpy $MiKTeXVersion "2.9"
125 StrCpy $LaTeXName "MiKTeX 2.9"
129 ${if} $PathLaTeX != ""
130 StrCpy $String $PathLaTeX
131 StrCpy $Search "x64" # search if it is 64bit MiKTeX
132 Call StrPoint # Function from LyXUtils.nsh
133 ${if} $Pointer != "-1" # if something was found
134 StrCpy $Is64bit "true"
136 StrCpy $LaTeXInstalled "MiKTeX"
137 # on some installations the path ends with a "\" on some not
138 # therefore assure that we remove it if it exists
139 StrCpy $0 $PathLaTeX "" -1
141 StrCpy $PathLaTeX "$PathLaTeX" -1 # delete "\"
145 # test if TeXLive is installed
146 # TeXLive can be installed so that it appears in the PATH variable and/or only as current user.
147 # The safest method is to first check for the PATH because this is independent of the TeXLive version.
149 SetRegView 64 # the PATH is in the 64bit registry section
151 ${if} $PathLaTeX == ""
152 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
153 StrCpy $Search "TeXLive"
154 Call LaTeXCheck # function from LyXUtils.nsh
156 # check for the current user Path variable
157 ${if} $PathLaTeX == ""
158 ReadRegStr $String HKCU "Environment" "Path"
159 StrCpy $Search "texlive"
161 Call LaTeXCheck # function from LyXUtils.nsh
163 # check if it was installed to the system
165 SetRegView 32 # TeXLive is a 32bit application
167 ${if} $PathLaTeX == ""
168 ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
170 ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
173 StrCpy $String $String -28 # remove '\tlpkg\installer\uninst.bat"'
174 StrCpy $String $String "" 1 # remove the leading quote
176 StrCpy $PathLaTeX "$String\bin\win32"
177 # check if the latex.exe exists in the $PathLaTeX folder
178 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
183 # finally set the name
184 ${if} $PathLaTeX != ""
185 ${andif} $LaTeXName != "MiKTeX 2.8"
186 ${andif} $LaTeXName != "MiKTeX 2.9"
187 StrCpy $LaTeXInstalled "TeXLive"
188 ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
190 ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
193 StrCpy $LaTeXName "TeXLive $String"
195 StrCpy $LaTeXName "TeXLive"
201 # -------------------------------------------
203 !if ${SETUPTYPE} == BUNDLE
205 Function InstallMiKTeX
206 # installs MiKTeX if not already installed
208 ${if} $PathLaTeX == ""
209 # launch MiKTeX's installer
210 MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
211 ExecWait ${MiKTeXInstall}
212 # test if MiKTeX is installed
215 SetRegView 32 # we install the 32bit version of MiKTeX
217 ${if} $PathLaTeX != ""
218 # special entry that it was installed together with LyX
219 # so that we can later uninstall it together with LyX
220 ${if} $MiKTeXUser == "HKCU"
221 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
223 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
225 StrCpy $LaTeXInstalled "MiKTeX"
226 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
228 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
229 SetOutPath $TEMP # to be able to delete the $INSTDIR
232 ${endif} # endif $PathLaTeX != ""
237 !endif # endif ${SETUPTYPE} == BUNDLE
239 # ------------------------------
241 Function ConfigureMiKTeX
242 # installs the LaTeX class files that are delivered with LyX,
243 # a Perl interpreter for splitindex
244 # and enable MiKTeX's automatic package installation
246 # install LyX's LaTeX class and style files and a Perl interpreter
247 ${if} $PathLaTeX != ""
248 ${if} $MultiUser.Privileges == "Admin"
249 ${orif} $MultiUser.Privileges == "Power"
250 ${if} $Is64bit == "true"
251 StrCpy $PathLaTeXLocal "$PathLaTeX" -15 # delete "\miktex\bin\x64"
253 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
256 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
259 # only install the LyX packages if they are not already installed
260 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
262 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
263 File "${FILES_DVIPOST_PKG}\dvipost.sty"
264 # files in Resources\tex
265 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
266 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
269 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\generic\babel\belarusian.ldf"
270 SetOutPath "$PathLaTeXLocal\tex\generic\babel"
271 File "${FILES_DVIPOST_PKG}\belarusian.ldf"
272 File "${FILES_DVIPOST_PKG}\belarusian.sty"
275 # this is a replacement therefore do this in every case
276 SetOutPath "$PathLaTeXLocal\tex\generic\babel"
277 File "${FILES_DVIPOST_PKG}\magyar.ldf"
279 # only install a Perl interpreter if it is not already installed
280 # this is only possible if MikTeX _and_ LyX is installed with the same privileges
282 SetRegView 32 # FIXME: recheck this if the 64bit version of MiKTeX is out of beta state
284 ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\MiKTeX $MiKTeXVersion" "DisplayVersion"
285 ${if} $MultiUser.Privileges != "Admin"
286 ${andif} $MultiUser.Privileges != "Power"
288 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
289 MessageBox MB_OK|MB_ICONINFORMATION "$(MultipleIndexesNotAvailable)"
292 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
293 ${if} $Is64bit == "true"
294 StrCpy $3 "$PathLaTeX" -15 # delete "\miktex\bin\x64"
296 StrCpy $3 "$PathLaTeX" -11 # delete "\miktex\bin"
299 File /r ${FILES_MIKTEX}
300 # move the files to the correct location for 64bit
301 ${if} $Is64bit == "true"
302 CopyFiles /SILENT /FILESONLY "$3\miktex\bin\*.*" "$PathLaTeX"
303 CreateDirectory "$3\miktex\bin\x64\lib"
304 CopyFiles /SILENT "$3\miktex\bin\lib\*.*" "$3\miktex\bin\x64\lib"
305 RMDir /r "$3\miktex\bin\lib"
306 Delete "$3\miktex\bin\*.*"
310 ${else} # if admin or power user
311 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
312 SetOutPath "$PathLaTeXLocal"
313 File /r ${FILES_MIKTEX}
314 # move the files to the correct location for 64bit
315 ${if} $Is64bit == "true"
316 CopyFiles /SILENT /FILESONLY "$PathLaTeXLocal\miktex\bin\*.*" "$PathLaTeX"
317 CreateDirectory "$PathLaTeXLocal\miktex\bin\x64\lib"
318 CopyFiles /SILENT "$PathLaTeXLocal\miktex\bin\lib\*.*" "$PathLaTeXLocal\miktex\bin\x64\lib"
319 RMDir /r "$PathLaTeXLocal\miktex\bin\lib"
320 Delete "$PathLaTeXLocal\miktex\bin\*.*"
325 # refresh MiKTeX's file name database (do this always to assure everything is in place)
326 ${if} $MultiUser.Privileges != "Admin"
327 ${andif} $MultiUser.Privileges != "Power"
328 # call the non-admin version
329 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
331 ${if} $MiKTeXUser != "HKCU" # call the admin version
332 nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
334 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
337 Pop $UpdateFNDBReturn # Return value
339 ${endif} # end if $PathLaTeX != ""
341 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first) and
342 # if there is not package repository (MiKTeX's primary package repository) then set it
344 ${andif} $Is64bit == "true"
349 ${if} $MiKTeXUser == "HKCU" # if only for current user
350 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
351 ReadRegStr $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository"
353 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
354 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
357 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
358 ReadRegStr $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository"
360 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
361 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
363 # we need to state that missing packages should be installed for all users too
364 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoAdmin" "t"
367 # update MiKTeX's package file list
368 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
370 # we must return to 32bit because LyX is a 32bit application
375 # ------------------------------
377 Function ConfigureTeXLive
378 # installs the LaTeX class files that are delivered with LyX
379 # (TeXLive comes already with a Perl interpreter.)
381 ${if} $PathLaTeX != ""
382 StrCpy $PathLaTeXLocal "$PathLaTeX" -10 # delete "\bin\win32"
384 # only install the LyX packages if they are not already installed
385 ${ifnot} ${FileExists} "$PathLaTeXLocal\texmf-dist\tex\latex\lyx\broadway.cls"
387 SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\dvipost"
388 File "${FILES_DVIPOST_PKG}\dvipost.sty"
389 # files in Resources\tex
390 SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
391 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
395 # update TeXLive's package file list
396 ExecWait '$PathLaTeX\texhash'
399 ExecWait '$PathLaTeX\tlmgr update --all'
403 # ------------------------------
405 Function UpdateMiKTeX
406 # asks to update MiKTeX
408 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
410 # the update wizard is started by the miktex-update.exe
411 ${if} $MultiUser.Privileges != "Admin"
412 ${andif} $MultiUser.Privileges != "Power"
413 # call the non-admin version
414 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
416 ${if} $MiKTeXUser != "HKCU" # call the admin version
417 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"'
419 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'