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 # test if MiKTeX is installed
31 # reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
32 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
33 StrCpy $Search "miktex"
34 Call LaTeXCheck # sets the path to the latex.exe to $PathLaTeX # Function from LyXUtils.nsh
36 ${if} $PathLaTeX != ""
37 # check if MiKTeX 2.8 or newer is installed
40 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
46 ${if} $String == "2.8"
47 StrCpy $MiKTeXVersion "2.8"
48 StrCpy $LaTeXName "MiKTeX 2.8"
50 ${if} $String == "2.9"
51 StrCpy $MiKTeXVersion "2.9"
52 StrCpy $LaTeXName "MiKTeX 2.9"
56 ${if} $PathLaTeX != ""
57 StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
58 ${else} # check if MiKTeX is installed only for the current user
59 ReadRegStr $String HKCU "Environment" "Path"
60 StrCpy $Search "miktex"
61 Call LaTeXCheck # function from LyXUtils.nsh
62 ${if} $PathLaTeX != ""
63 StrCpy $MiKTeXUser "HKCU"
66 ${if} $LaTeXName == "" # check for the MiKTeX version
69 EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
75 ${if} $String == "2.8"
76 StrCpy $MiKTeXVersion "2.8"
77 StrCpy $LaTeXName "MiKTeX 2.8"
79 ${if} $String == "2.9"
80 StrCpy $MiKTeXVersion "2.9"
81 StrCpy $LaTeXName "MiKTeX 2.9"
85 ${if} $PathLaTeX != ""
86 StrCpy $LaTeXInstalled "MiKTeX"
87 # on some installations the path ends with a "\" on some not
88 # therefore assure that we remove it if it exists
89 StrCpy $0 $PathLaTeX "" -1
91 StrCpy $PathLaTeX "$PathLaTeX" -1 # delete "\"
95 # test if TeXLive is installed
96 # TeXLive can be installed so that it appears in the PATH variable and/or only as current user.
97 # The safest method is to first check for the PATH because this is independent of the TeXLive version.
98 ${if} $PathLaTeX == ""
99 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
100 StrCpy $Search "TeXLive"
101 Call LaTeXCheck # function from LyXUtils.nsh
103 # check for the current user Path variable
104 ${if} $PathLaTeX == ""
105 ReadRegStr $String HKCU "Environment" "Path"
106 StrCpy $Search "texlive"
108 Call LaTeXCheck # function from LyXUtils.nsh
110 # check if it was installed to the system
111 ${if} $PathLaTeX == ""
112 ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
114 ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
117 StrCpy $String $String -28 # remove '\tlpkg\installer\uninst.bat"'
118 StrCpy $String $String "" 1 # remove the leading quote
120 StrCpy $PathLaTeX "$String\bin\win32"
121 # check if the latex.exe exists in the $PathLaTeX folder
122 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
127 # finally set the name
128 ${if} $PathLaTeX != ""
129 ${andif} $LaTeXName != "MiKTeX 2.8"
130 ${andif} $LaTeXName != "MiKTeX 2.9"
131 StrCpy $LaTeXInstalled "TeXLive"
132 ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
134 ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
137 StrCpy $LaTeXName "TeXLive $String"
139 StrCpy $LaTeXName "TeXLive"
145 # -------------------------------------------
147 !if ${SETUPTYPE} == BUNDLE
149 Function InstallMiKTeX
150 # installs MiKTeX if not already installed
152 ${if} $PathLaTeX == ""
153 # launch MiKTeX's installer
154 MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
155 ExecWait ${MiKTeXInstall}
156 # test if MiKTeX is installed
158 ${if} $PathLaTeX != ""
159 # special entry that it was installed together with LyX
160 # so that we can later uninstall it together with LyX
161 ${if} $MiKTeXUser == "HKCU"
162 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
164 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
166 StrCpy $LaTeXInstalled "MiKTeX"
167 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
169 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
170 SetOutPath $TEMP # to be able to delete the $INSTDIR
173 ${endif} # endif $PathLaTeX != ""
178 !endif # endif ${SETUPTYPE} == BUNDLE
180 # ------------------------------
182 Function ConfigureMiKTeX
183 # installs the LaTeX class files that are delivered with LyX,
184 # a Perl interpreter for splitindex
185 # and enable MiKTeX's automatic package installation
187 # install LyX's LaTeX class and style files and a Perl interpreter
188 ${if} $PathLaTeX != ""
189 ${if} $MultiUser.Privileges == "Admin"
190 ${orif} $MultiUser.Privileges == "Power"
191 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
193 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
196 # only install the LyX packages if they are not already installed
197 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
199 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
200 File "${FILES_DVIPOST_PKG}\dvipost.sty"
201 # files in Resources\tex
202 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
203 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
206 # only install a Perl interpreter if it is not already installed
207 # this is only possible if MikTeX _and_ LyX is installed with the same privileges
208 ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\MiKTeX $MiKTeXVersion" "DisplayVersion"
209 ${if} $MultiUser.Privileges != "Admin"
210 ${andif} $MultiUser.Privileges != "Power"
212 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
213 MessageBox MB_OK|MB_ICONINFORMATION "$(MultipleIndexesNotAvailable)"
216 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
217 SetOutPath "$PathLaTeXLocal"
218 File /r ${FILES_MIKTEX}
222 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
223 SetOutPath "$PathLaTeXLocal"
224 File /r ${FILES_MIKTEX}
228 # refresh MiKTeX's file name database (do this always to assure everything is in place)
229 ${if} $MultiUser.Privileges != "Admin"
230 ${andif} $MultiUser.Privileges != "Power"
231 # call the non-admin version
232 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
234 ${if} $MiKTeXUser != "HKCU" # call the admin version
235 nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
237 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
240 Pop $UpdateFNDBReturn # Return value
242 ${endif} # end if $PathLaTeX != ""
244 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
245 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
246 ${if} $MiKTeXUser != "HKCU"
247 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
249 # set package repository (MiKTeX's primary package repository)
250 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
251 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
252 ${if} $MiKTeXUser != "HKCU"
253 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
254 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
257 # update MiKTeX's package file list
258 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
259 # the following feature is planned to be used for a possible Live version
260 # copy LaTeX-packages needed by LyX
261 # SetOutPath "$INSTDIR"
262 # File /r "${LaTeXPackagesDir}"
266 # ------------------------------
268 Function ConfigureTeXLive
269 # installs the LaTeX class files that are delivered with LyX
270 # (TeXLive comes already with a Perl interpreter.)
272 ${if} $PathLaTeX != ""
273 StrCpy $PathLaTeXLocal "$PathLaTeX" -10 # delete "\bin\win32"
275 # only install the LyX packages if they are not already installed
276 ${ifnot} ${FileExists} "$PathLaTeXLocal\texmf-dist\tex\latex\lyx\broadway.cls"
278 SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\dvipost"
279 File "${FILES_DVIPOST_PKG}\dvipost.sty"
280 # files in Resources\tex
281 SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
282 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
286 # update TeXLive's package file list
287 ExecWait '$PathLaTeX\texhash'
290 ExecWait '$PathLaTeX\tlmgr update --all'
294 # ------------------------------
296 Function UpdateMiKTeX
297 # asks to update MiKTeX
299 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
301 # the update wizard is started by the miktex-update.exe
302 ${if} $MultiUser.Privileges != "Admin"
303 ${andif} $MultiUser.Privileges != "Power"
304 # call the non-admin version
305 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
307 ${if} $MiKTeXUser != "HKCU" # call the admin version
308 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"'
310 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'