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
31 SetRegView 64 # the PATH is in the 64bit registry section
33 # test if MiKTeX is installed
34 # reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
35 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
36 StrCpy $Search "miktex"
37 Call LaTeXCheck # sets the path to the latex.exe to $PathLaTeX # Function from LyXUtils.nsh
39 # check for 32bit MiKTeX
40 ${if} $PathLaTeX != ""
44 # check if MiKTeX 2.8 or newer is installed
47 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
53 ${if} $String == "2.8"
54 StrCpy $MiKTeXVersion "2.8"
55 StrCpy $LaTeXName "MiKTeX 2.8"
57 ${if} $String == "2.9"
58 StrCpy $MiKTeXVersion "2.9"
59 StrCpy $LaTeXName "MiKTeX 2.9"
63 # check for 64bit MiKTeX
64 ${if} $PathLaTeX == ""
68 # check if MiKTeX 2.8 or newer is installed
71 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
77 ${if} $String == "2.8"
78 StrCpy $MiKTeXVersion "2.8"
79 StrCpy $LaTeXName "MiKTeX 2.8"
81 ${if} $String == "2.9"
82 StrCpy $MiKTeXVersion "2.9"
83 StrCpy $LaTeXName "MiKTeX 2.9"
87 ${if} $PathLaTeX != ""
88 StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
89 ${else} # check if MiKTeX is installed only for the current user
91 SetRegView 64 # the PATH is in the 64bit registry section
93 ReadRegStr $String HKCU "Environment" "Path"
94 StrCpy $Search "miktex"
95 Call LaTeXCheck # function from LyXUtils.nsh
96 ${if} $PathLaTeX != ""
97 StrCpy $MiKTeXUser "HKCU"
100 ${if} $LaTeXName == "" # check for the MiKTeX version
103 EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
109 ${if} $String == "2.8"
110 StrCpy $MiKTeXVersion "2.8"
111 StrCpy $LaTeXName "MiKTeX 2.8"
113 ${if} $String == "2.9"
114 StrCpy $MiKTeXVersion "2.9"
115 StrCpy $LaTeXName "MiKTeX 2.9"
119 ${if} $PathLaTeX != ""
120 StrCpy $LaTeXInstalled "MiKTeX"
121 # on some installations the path ends with a "\" on some not
122 # therefore assure that we remove it if it exists
123 StrCpy $0 $PathLaTeX "" -1
125 StrCpy $PathLaTeX "$PathLaTeX" -1 # delete "\"
129 # test if TeXLive is installed
130 # TeXLive can be installed so that it appears in the PATH variable and/or only as current user.
131 # The safest method is to first check for the PATH because this is independent of the TeXLive version.
133 SetRegView 64 # the PATH is in the 64bit registry section
135 ${if} $PathLaTeX == ""
136 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
137 StrCpy $Search "TeXLive"
138 Call LaTeXCheck # function from LyXUtils.nsh
140 # check for the current user Path variable
141 ${if} $PathLaTeX == ""
142 ReadRegStr $String HKCU "Environment" "Path"
143 StrCpy $Search "texlive"
145 Call LaTeXCheck # function from LyXUtils.nsh
147 # check if it was installed to the system
149 SetRegView 32 # TeXLive is a 32bit application
151 ${if} $PathLaTeX == ""
152 ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
154 ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
157 StrCpy $String $String -28 # remove '\tlpkg\installer\uninst.bat"'
158 StrCpy $String $String "" 1 # remove the leading quote
160 StrCpy $PathLaTeX "$String\bin\win32"
161 # check if the latex.exe exists in the $PathLaTeX folder
162 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
167 # finally set the name
168 ${if} $PathLaTeX != ""
169 ${andif} $LaTeXName != "MiKTeX 2.8"
170 ${andif} $LaTeXName != "MiKTeX 2.9"
171 StrCpy $LaTeXInstalled "TeXLive"
172 ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
174 ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
177 StrCpy $LaTeXName "TeXLive $String"
179 StrCpy $LaTeXName "TeXLive"
185 # -------------------------------------------
187 !if ${SETUPTYPE} == BUNDLE
189 Function InstallMiKTeX
190 # installs MiKTeX if not already installed
192 ${if} $PathLaTeX == ""
193 # launch MiKTeX's installer
194 MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
195 ExecWait ${MiKTeXInstall}
196 # test if MiKTeX is installed
199 SetRegView 32 # we install the 32bit version of MiKTeX
201 ${if} $PathLaTeX != ""
202 # special entry that it was installed together with LyX
203 # so that we can later uninstall it together with LyX
204 ${if} $MiKTeXUser == "HKCU"
205 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
207 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
209 StrCpy $LaTeXInstalled "MiKTeX"
210 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
212 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
213 SetOutPath $TEMP # to be able to delete the $INSTDIR
216 ${endif} # endif $PathLaTeX != ""
221 !endif # endif ${SETUPTYPE} == BUNDLE
223 # ------------------------------
225 Function ConfigureMiKTeX
226 # installs the LaTeX class files that are delivered with LyX,
227 # a Perl interpreter for splitindex
228 # and enable MiKTeX's automatic package installation
230 # install LyX's LaTeX class and style files and a Perl interpreter
231 ${if} $PathLaTeX != ""
232 ${if} $MultiUser.Privileges == "Admin"
233 ${orif} $MultiUser.Privileges == "Power"
234 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
236 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
239 # only install the LyX packages if they are not already installed
240 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
242 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
243 File "${FILES_DVIPOST_PKG}\dvipost.sty"
244 # files in Resources\tex
245 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
246 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
249 # only install a Perl interpreter if it is not already installed
250 # this is only possible if MikTeX _and_ LyX is installed with the same privileges
252 SetRegView 32 # FIXME: recheck this if the 64bit version of MiKTeX is out of beta state
254 ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\MiKTeX $MiKTeXVersion" "DisplayVersion"
255 ${if} $MultiUser.Privileges != "Admin"
256 ${andif} $MultiUser.Privileges != "Power"
258 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
259 MessageBox MB_OK|MB_ICONINFORMATION "$(MultipleIndexesNotAvailable)"
262 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
263 SetOutPath "$PathLaTeXLocal"
264 File /r ${FILES_MIKTEX}
268 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
269 SetOutPath "$PathLaTeXLocal"
270 File /r ${FILES_MIKTEX}
274 # refresh MiKTeX's file name database (do this always to assure everything is in place)
275 ${if} $MultiUser.Privileges != "Admin"
276 ${andif} $MultiUser.Privileges != "Power"
277 # call the non-admin version
278 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
280 ${if} $MiKTeXUser != "HKCU" # call the admin version
281 nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
283 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
286 Pop $UpdateFNDBReturn # Return value
288 ${endif} # end if $PathLaTeX != ""
290 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first) and
291 # if there is not package repository (MiKTeX's primary package repository) then set it
292 # FIXME: support 64bit MiKTeX if it is out of beta state
293 ${if} $MiKTeXUser == "HKCU" # if only for current user
294 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
295 ReadRegStr $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository"
297 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
298 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
301 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
302 ReadRegStr $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository"
304 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
305 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
307 # we need to state that missing packages should be installed for all users too
308 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoAdmin" "t"
311 # update MiKTeX's package file list
312 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
316 # ------------------------------
318 Function ConfigureTeXLive
319 # installs the LaTeX class files that are delivered with LyX
320 # (TeXLive comes already with a Perl interpreter.)
322 ${if} $PathLaTeX != ""
323 StrCpy $PathLaTeXLocal "$PathLaTeX" -10 # delete "\bin\win32"
325 # only install the LyX packages if they are not already installed
326 ${ifnot} ${FileExists} "$PathLaTeXLocal\texmf-dist\tex\latex\lyx\broadway.cls"
328 SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\dvipost"
329 File "${FILES_DVIPOST_PKG}\dvipost.sty"
330 # files in Resources\tex
331 SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
332 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
336 # update TeXLive's package file list
337 ExecWait '$PathLaTeX\texhash'
340 ExecWait '$PathLaTeX\tlmgr update --all'
344 # ------------------------------
346 Function UpdateMiKTeX
347 # asks to update MiKTeX
349 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
351 # the update wizard is started by the miktex-update.exe
352 ${if} $MultiUser.Privileges != "Admin"
353 ${andif} $MultiUser.Privileges != "Power"
354 # call the non-admin version
355 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
357 ${if} $MiKTeXUser != "HKCU" # call the admin version
358 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"'
360 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'