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
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 ${if} $PathLaTeX != ""
40 # check if MiKTeX 2.8 or newer is installed
43 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
49 ${if} $String == "2.8"
50 StrCpy $MiKTeXVersion "2.8"
51 StrCpy $LaTeXName "MiKTeX 2.8"
53 ${if} $String == "2.9"
54 StrCpy $MiKTeXVersion "2.9"
55 StrCpy $LaTeXName "MiKTeX 2.9"
59 ${if} $PathLaTeX != ""
60 StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
61 ${else} # check if MiKTeX is installed only for the current user
62 ReadRegStr $String HKCU "Environment" "Path"
63 StrCpy $Search "miktex"
64 Call LaTeXCheck # function from LyXUtils.nsh
65 ${if} $PathLaTeX != ""
66 StrCpy $MiKTeXUser "HKCU"
69 ${if} $LaTeXName == "" # check for the MiKTeX version
72 EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
78 ${if} $String == "2.8"
79 StrCpy $MiKTeXVersion "2.8"
80 StrCpy $LaTeXName "MiKTeX 2.8"
82 ${if} $String == "2.9"
83 StrCpy $MiKTeXVersion "2.9"
84 StrCpy $LaTeXName "MiKTeX 2.9"
88 ${if} $PathLaTeX != ""
89 StrCpy $LaTeXInstalled "MiKTeX"
90 # on some installations the path ends with a "\" on some not
91 # therefore assure that we remove it if it exists
92 StrCpy $0 $PathLaTeX "" -1
94 StrCpy $PathLaTeX "$PathLaTeX" -1 # delete "\"
98 # test if TeXLive is installed
99 # TeXLive can be installed so that it appears in the PATH variable and/or only as current user.
100 # The safest method is to first check for the PATH because this is independent of the TeXLive version.
101 ${if} $PathLaTeX == ""
102 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
103 StrCpy $Search "TeXLive"
104 Call LaTeXCheck # function from LyXUtils.nsh
106 # check for the current user Path variable
107 ${if} $PathLaTeX == ""
108 ReadRegStr $String HKCU "Environment" "Path"
109 StrCpy $Search "texlive"
111 Call LaTeXCheck # function from LyXUtils.nsh
113 # check if it was installed to the system
114 ${if} $PathLaTeX == ""
115 ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
117 ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
120 StrCpy $String $String -28 # remove '\tlpkg\installer\uninst.bat"'
121 StrCpy $String $String "" 1 # remove the leading quote
123 StrCpy $PathLaTeX "$String\bin\win32"
124 # check if the latex.exe exists in the $PathLaTeX folder
125 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
130 # finally set the name
131 ${if} $PathLaTeX != ""
132 ${andif} $LaTeXName != "MiKTeX 2.8"
133 ${andif} $LaTeXName != "MiKTeX 2.9"
134 StrCpy $LaTeXInstalled "TeXLive"
135 ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
137 ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
140 StrCpy $LaTeXName "TeXLive $String"
142 StrCpy $LaTeXName "TeXLive"
148 # -------------------------------------------
150 !if ${SETUPTYPE} == BUNDLE
152 Function InstallMiKTeX
153 # installs MiKTeX if not already installed
155 ${if} $PathLaTeX == ""
156 # launch MiKTeX's installer
157 MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
158 ExecWait ${MiKTeXInstall}
159 # test if MiKTeX is installed
161 ${if} $PathLaTeX != ""
162 # special entry that it was installed together with LyX
163 # so that we can later uninstall it together with LyX
164 ${if} $MiKTeXUser == "HKCU"
165 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
167 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
169 StrCpy $LaTeXInstalled "MiKTeX"
170 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
172 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
173 SetOutPath $TEMP # to be able to delete the $INSTDIR
176 ${endif} # endif $PathLaTeX != ""
181 !endif # endif ${SETUPTYPE} == BUNDLE
183 # ------------------------------
185 Function ConfigureMiKTeX
186 # installs the LaTeX class files that are delivered with LyX,
187 # a Perl interpreter for splitindex
188 # and enable MiKTeX's automatic package installation
190 # install LyX's LaTeX class and style files and a Perl interpreter
191 ${if} $PathLaTeX != ""
192 ${if} $MultiUser.Privileges == "Admin"
193 ${orif} $MultiUser.Privileges == "Power"
194 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
196 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
199 # only install the LyX packages if they are not already installed
200 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
202 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
203 File "${FILES_DVIPOST_PKG}\dvipost.sty"
204 # files in Resources\tex
205 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
206 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
209 # only install a Perl interpreter if it is not already installed
210 # this is only possible if MikTeX _and_ LyX is installed with the same privileges
211 ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\MiKTeX $MiKTeXVersion" "DisplayVersion"
212 ${if} $MultiUser.Privileges != "Admin"
213 ${andif} $MultiUser.Privileges != "Power"
215 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
216 MessageBox MB_OK|MB_ICONINFORMATION "$(MultipleIndexesNotAvailable)"
219 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
220 SetOutPath "$PathLaTeXLocal"
221 File /r ${FILES_MIKTEX}
225 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
226 SetOutPath "$PathLaTeXLocal"
227 File /r ${FILES_MIKTEX}
231 # refresh MiKTeX's file name database (do this always to assure everything is in place)
232 ${if} $MultiUser.Privileges != "Admin"
233 ${andif} $MultiUser.Privileges != "Power"
234 # call the non-admin version
235 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
237 ${if} $MiKTeXUser != "HKCU" # call the admin version
238 nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
240 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
243 Pop $UpdateFNDBReturn # Return value
245 ${endif} # end if $PathLaTeX != ""
247 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
248 ${if} $MiKTeXUser == "HKCU" # if only for current user
249 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
251 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
252 # we need to state that missing packages should be installed for all users too
253 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoAdmin" "t"
255 # set package repository (MiKTeX's primary package repository)
256 ${if} $MiKTeXUser == "HKCU" # if only for current user
257 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
258 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
260 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
261 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
264 # update MiKTeX's package file list
265 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
266 # the following feature is planned to be used for a possible Live version
267 # copy LaTeX-packages needed by LyX
268 # SetOutPath "$INSTDIR"
269 # File /r "${LaTeXPackagesDir}"
273 # ------------------------------
275 Function ConfigureTeXLive
276 # installs the LaTeX class files that are delivered with LyX
277 # (TeXLive comes already with a Perl interpreter.)
279 ${if} $PathLaTeX != ""
280 StrCpy $PathLaTeXLocal "$PathLaTeX" -10 # delete "\bin\win32"
282 # only install the LyX packages if they are not already installed
283 ${ifnot} ${FileExists} "$PathLaTeXLocal\texmf-dist\tex\latex\lyx\broadway.cls"
285 SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\dvipost"
286 File "${FILES_DVIPOST_PKG}\dvipost.sty"
287 # files in Resources\tex
288 SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
289 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
293 # update TeXLive's package file list
294 ExecWait '$PathLaTeX\texhash'
297 ExecWait '$PathLaTeX\tlmgr update --all'
301 # ------------------------------
303 Function UpdateMiKTeX
304 # asks to update MiKTeX
306 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
308 # the update wizard is started by the miktex-update.exe
309 ${if} $MultiUser.Privileges != "Admin"
310 ${andif} $MultiUser.Privileges != "Power"
311 # call the non-admin version
312 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
314 ${if} $MiKTeXUser != "HKCU" # call the admin version
315 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"'
317 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'