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.8 or newer is installed
37 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
43 ${if} $String == "2.8"
44 StrCpy $MiKTeXVersion "2.8"
45 StrCpy $LaTeXName "MiKTeX 2.8"
47 ${if} $String == "2.9"
48 StrCpy $MiKTeXVersion "2.9"
49 StrCpy $LaTeXName "MiKTeX 2.9"
53 ${if} $PathLaTeX != ""
54 StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
55 ${else} # check if MiKTeX is installed only for the current user
56 ReadRegStr $String HKCU "Environment" "Path"
57 StrCpy $Search "miktex"
58 Call LaTeXCheck # function from LyXUtils.nsh
59 ${if} $PathLaTeX != ""
60 StrCpy $MiKTeXUser "HKCU"
63 ${if} $LaTeXName == "" # check for the MiKTeX version
66 EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
72 ${if} $String == "2.8"
73 StrCpy $MiKTeXVersion "2.8"
74 StrCpy $LaTeXName "MiKTeX 2.8"
76 ${if} $String == "2.9"
77 StrCpy $MiKTeXVersion "2.9"
78 StrCpy $LaTeXName "MiKTeX 2.9"
82 ${if} $PathLaTeX != ""
83 StrCpy $LaTeXInstalled "MiKTeX"
86 # test if TeXLive is installed
87 # as described at TeXLives' homepage there should be an entry in the PATH
88 ${if} $PathLaTeX == ""
89 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
90 StrCpy $Search "TeXLive"
91 Call LaTeXCheck # function from LyXUtils.nsh
93 # check for the current user Path variable (the case when it is a live CD/DVD)
94 ${if} $PathLaTeX == ""
95 ReadRegStr $String HKCU "Environment" "Path"
96 StrCpy $Search "texlive"
98 Call LaTeXCheck # function from LyXUtils.nsh
100 # check if the variable TLroot exists (the case when it is installed using the program "tlpmgui")
101 ${if} $PathLaTeX == ""
102 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "TLroot"
104 ReadRegStr $String HKCU "Environment" "TLroot" # the case when installed without admin permissions
106 StrCpy $PathLaTeX "$String\bin\win32"
107 # check if the latex.exe exists in the $PathLaTeX folder
108 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
113 ${if} $PathLaTeX != ""
114 ${andif} $LaTeXName != "MiKTeX 2.8"
115 ${andif} $LaTeXName != "MiKTeX 2.9"
116 StrCpy $LaTeXName "TeXLive"
121 # -------------------------------------------
123 !if ${SETUPTYPE} == BUNDLE
125 Function InstallMiKTeX
126 # installs MiKTeX if not already installed
128 ${if} $PathLaTeX == ""
129 # launch MiKTeX's installer
130 MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
131 ExecWait ${MiKTeXInstall}
132 # test if MiKTeX is installed
133 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
134 StrCpy $Search "miktex"
135 Call LaTeXCheck # function from LyXUtils.nsh
136 ${if} $PathLaTeX != ""
137 StrCpy $MiKTeXUser "HKLM"
139 StrCpy $MiKTeXUser "HKCU"
140 ReadRegStr $String HKCU "Environment" "Path"
141 StrCpy $Search "miktex"
142 Call LaTeXCheck # function from LyXUtils.nsh
144 ${if} $PathLaTeX != ""
145 # set package repository (MiKTeX's primary package repository)
146 ${if} $MiKTeXUser == "HKCU"
147 # special entry that it was installed together with LyX
148 # so that we can later uninstall it together with LyX
149 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
151 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
153 StrCpy $LaTeXInstalled "MiKTeX"
154 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
156 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
157 SetOutPath $TEMP # to be able to delete the $INSTDIR
160 ${endif} # endif $PathLaTeX != ""
165 !endif # endif ${SETUPTYPE} == BUNDLE
167 # ------------------------------
169 Function ConfigureMiKTeX
170 # installs the LaTeX class files that are delivered with LyX,
171 # a Perl interpreter for splitindex
172 # and enable MiKTeX's automatic package installation
174 # install LyX's LaTeX class and style files and a Perl interpreter
175 ${if} $PathLaTeX != ""
176 ${if} $MultiUser.Privileges == "Admin"
177 ${orif} $MultiUser.Privileges == "Power"
178 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
180 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
183 # only install the LyX packages if they are not already installed
184 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
186 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
187 File "${FILES_DVIPOST_PKG}\dvipost.sty"
188 # LyX files in Resources\tex
189 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
190 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
193 # only install a Perl interpreter if it is not already installed
194 # this is only possible if MikTeX _and_ LyX is installed with the same privileges
195 ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\MiKTeX $MiKTeXVersion" "DisplayVersion"
196 ${if} $MultiUser.Privileges != "Admin"
197 ${andif} $MultiUser.Privileges != "Power"
199 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
200 MessageBox MB_OK|MB_ICONINFORMATION "$(MultipleIndexesNotAvailable)"
203 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
204 SetOutPath "$PathLaTeXLocal"
205 File /r ${FILES_MIKTEX}
209 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
210 SetOutPath "$PathLaTeXLocal"
211 File /r ${FILES_MIKTEX}
215 # refresh MiKTeX's file name database (do this always to assure everything is in place)
216 ${if} $MultiUser.Privileges != "Admin"
217 ${andif} $MultiUser.Privileges != "Power"
218 # call the non-admin version
219 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
221 ${if} $MiKTeXUser != "HKCU" # call the admin version
222 nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
224 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
227 Pop $UpdateFNDBReturn # Return value
231 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
232 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
233 ${if} $MiKTeXUser != "HKCU"
234 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
236 # set package repository (MiKTeX's primary package repository)
237 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
238 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
239 ${if} $MiKTeXUser != "HKCU"
240 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
241 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
244 # enable MiKTeX's automatic package installation
245 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
246 # the following feature is planned to be used for a possible CD-version
247 # copy LaTeX-packages needed by LyX
248 # SetOutPath "$INSTDIR"
249 # File /r "${LaTeXPackagesDir}"
253 Function UpdateMiKTeX
254 # asks to update MiKTeX
256 ${if} $LaTeXInstalled == "MiKTeX"
257 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
259 StrCpy $0 $PathLaTeX -4 # remove "\bin"
260 # the update wizard is started by the miktex-update.exe
261 ${if} $MultiUser.Privileges != "Admin"
262 ${andif} $MultiUser.Privileges != "Power"
263 # call the non-admin version
264 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
266 ${if} $MiKTeXUser != "HKCU" # call the admin version
267 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"'
269 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'