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)
20 # - UpdateMiKTeX (asks to update MiKTeX)
22 # ---------------------------------------
25 # checks if MiKTeX or TeXLive is installed
27 # test if MiKTeX is installed
28 # reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
29 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
30 StrCpy $Search "miktex"
31 Call LaTeXCheck # sets the path to the latex.exe to $PathLaTeX # Function from LyXUtils.nsh
33 ${if} $PathLaTeX != ""
34 # check if MiKTeX 2.7 or newer is installed
37 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
43 ${if} $String == "2.7"
44 StrCpy $MiKTeXVersion "2.7"
45 StrCpy $LaTeXName "MiKTeX 2.7"
47 ${if} $String == "2.8"
48 StrCpy $MiKTeXVersion "2.8"
49 StrCpy $LaTeXName "MiKTeX 2.8"
51 ${if} $String == "2.9"
52 StrCpy $MiKTeXVersion "2.9"
53 StrCpy $LaTeXName "MiKTeX 2.9"
57 ${if} $PathLaTeX != ""
58 StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
59 ${else} # check if MiKTeX is installed only for the current user
60 ReadRegStr $String HKCU "Environment" "Path"
61 StrCpy $Search "miktex"
62 Call LaTeXCheck # function from LyXUtils.nsh
63 ${if} $PathLaTeX != ""
64 StrCpy $MiKTeXUser "HKCU"
67 ${if} $LaTeXName == "" # check for the MiKTeX version
70 EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
76 ${if} $String == "2.7"
77 StrCpy $MiKTeXVersion "2.7"
78 StrCpy $LaTeXName "MiKTeX 2.7"
80 ${if} $String == "2.8"
81 StrCpy $MiKTeXVersion "2.8"
82 StrCpy $LaTeXName "MiKTeX 2.8"
84 ${if} $String == "2.9"
85 StrCpy $MiKTeXVersion "2.9"
86 StrCpy $LaTeXName "MiKTeX 2.9"
90 ${if} $PathLaTeX != ""
91 StrCpy $LaTeXInstalled "MiKTeX"
94 # test if TeXLive is installed
95 # as described at TeXLives' homepage there should be an entry in the PATH
96 ${if} $PathLaTeX == ""
97 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
98 StrCpy $Search "TeXLive"
99 Call LaTeXCheck # function from LyXUtils.nsh
101 # check for the current user Path variable (the case when it is a live CD/DVD)
102 ${if} $PathLaTeX == ""
103 ReadRegStr $String HKCU "Environment" "Path"
104 StrCpy $Search "texlive"
106 Call LaTeXCheck # function from LyXUtils.nsh
108 # check if the variable TLroot exists (the case when it is installed using the program "tlpmgui")
109 ${if} $PathLaTeX == ""
110 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "TLroot"
112 ReadRegStr $String HKCU "Environment" "TLroot" # the case when installed without admin permissions
114 StrCpy $PathLaTeX "$String\bin\win32"
115 # check if the latex.exe exists in the $PathLaTeX folder
116 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
121 ${if} $PathLaTeX != ""
122 ${andif} $LaTeXName != "MiKTeX 2.7"
123 ${andif} $LaTeXName != "MiKTeX 2.8"
124 ${andif} $LaTeXName != "MiKTeX 2.9"
125 StrCpy $LaTeXName "TeXLive"
130 # -------------------------------------------
132 !if ${SETUPTYPE} == BUNDLE
134 Function InstallMiKTeX
135 # installs MiKTeX if not already installed
137 ${if} $PathLaTeX == ""
138 # launch MiKTeX's installer
139 MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
140 ExecWait ${MiKTeXInstall}
141 # test if MiKTeX is installed
142 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
143 StrCpy $Search "miktex"
144 Call LaTeXCheck # function from LyXUtils.nsh
145 ${if} $PathLaTeX != ""
146 StrCpy $MiKTeXUser "HKLM"
148 StrCpy $MiKTeXUser "HKCU"
149 ReadRegStr $String HKCU "Environment" "Path"
150 StrCpy $Search "miktex"
151 Call LaTeXCheck # function from LyXUtils.nsh
153 ${if} $PathLaTeX != ""
154 # set package repository (MiKTeX's primary package repository)
155 ${if} $MiKTeXUser == "HKCU"
156 # special entry that it was installed together with LyX
157 # so that we can later uninstall it together with LyX
158 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
160 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
162 StrCpy $LaTeXInstalled "MiKTeX"
163 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
165 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
166 SetOutPath $TEMP # to be able to delete the $INSTDIR
169 ${endif} # endif $PathLaTeX != ""
174 !endif # endif ${SETUPTYPE} == BUNDLE
176 # ------------------------------
178 Function ConfigureMiKTeX
179 # installs the LaTeX class files that are delivered with LyX,
180 # a Perl interpreter for splitindex
181 # and enable MiKTeX's automatic package installation
183 # install LyX's LaTeX class and style files and a Perl interpreter
184 ${if} $PathLaTeX != ""
185 ${if} $MultiUser.Privileges == "Admin"
186 ${orif} $MultiUser.Privileges == "Power"
187 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
189 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
192 # only install the LyX packages if they are not already installed
193 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
195 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
196 File "${FILES_DVIPOST_PKG}\dvipost.sty"
197 # LyX files in Resources\tex
198 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
199 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
202 # only install a Perl interpreter if it is not already installed
203 # this is only possible if miktex and LyX is installed with the same privileges
204 ${if} $MultiUser.Privileges != "Admin"
205 ${andif} $MultiUser.Privileges != "Power"
206 ${if} $PathLaTeX != "$LOCALAPPDATA\MiKTeX\$MiKTeXVersion\miktex\bin"
207 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
208 MessageBox MB_OK|MB_ICONINFORMATION "$(MultipleIndexesNotAvailable)"
211 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
212 SetOutPath "$PathLaTeXLocal"
213 File /r ${FILES_MIKTEX}
217 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
218 SetOutPath "$PathLaTeXLocal"
219 File /r ${FILES_MIKTEX}
223 # refresh MiKTeX's file name database (do this always to assure everything is in place)
224 ${if} $MultiUser.Privileges != "Admin"
225 ${andif} $MultiUser.Privileges != "Power"
226 # call the non-admin version
227 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
229 ${if} $MiKTeXUser != "HKCU" # call the admin version
230 nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
232 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
235 Pop $UpdateFNDBReturn # Return value
239 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
240 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
241 ${if} $MiKTeXUser != "HKCU"
242 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
244 # set package repository (MiKTeX's primary package repository)
245 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
246 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
247 ${if} $MiKTeXUser != "HKCU"
248 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
249 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
252 # enable MiKTeX's automatic package installation
253 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
254 # the following feature is planned to be used for a possible CD-version
255 # copy LaTeX-packages needed by LyX
256 # SetOutPath "$INSTDIR"
257 # File /r "${LaTeXPackagesDir}"
261 Function UpdateMiKTeX
262 # asks to update MiKTeX
264 ${if} $LaTeXInstalled == "MiKTeX"
265 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
267 StrCpy $0 $PathLaTeX -4 # remove "\bin"
268 # the update wizard is either started by the copystart_admin.exe
269 # or the miktex-update.exe (since MiKTeX 2.8)
270 ${if} $MultiUser.Privileges != "Admin"
271 ${andif} $MultiUser.Privileges != "Power"
272 # call the non-admin version
273 ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
274 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
276 ${if} $MiKTeXUser != "HKCU" # call the admin version
277 ExecWait '"$PathLaTeX\copystart_admin.exe" "$0\config\update.dat"'
278 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"' # run MiKTeX's update wizard
280 ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
281 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'