]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/LaTeX.nsh
Consider inset strings in simple find/replaceAll (#12049)
[features.git] / development / Win32 / packaging / installer / include / LaTeX.nsh
1 /*
2 LaTeX.nsh
3
4 Handling of LaTeX distributions
5 */
6
7 # This script contains the following functions:
8 #
9 # - LaTeXActions (checks if MiKTeX or TeXLive is installed)
10 #
11 # - ConfigureMiKTeX
12 #   (installs the LaTeX class files that are delivered with LyX,
13 #    a Perl interpreter for splitindex and pdfcrop
14 #    and enable MiKTeX's automatic package installation)
15 #
16 # - ConfigureTeXLive
17 #   (installs the LaTeX class files that are delivered with LyX)
18
19 # ---------------------------------------
20
21 Function LaTeXActions
22  # checks if MiKTeX or TeXLive is installed
23
24   StrCpy $Is64bit "false"
25   
26   ${if} ${RunningX64}
27    SetRegView 64 # the PATH is in the 64bit registry section
28   ${endif}
29   # test if MiKTeX is installed
30   # reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
31   ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
32   StrCpy $Search "miktex"
33   Call LaTeXCheck # sets the path to the latex.exe to $PathLaTeX # Function from LyXUtils.nsh
34   
35   StrCpy $String $PathLaTeX
36   StrCpy $Search "x64" # search if it is 64bit MiKTeX
37   Call StrPoint # Function from LyXUtils.nsh
38   ${if} $Pointer != "-1" # if something was found
39    StrCpy $Is64bit "true"
40   ${endif}
41   
42   # check for 32bit MiKTeX
43   ${if} $PathLaTeX != ""
44   ${andif} $Is64bit != "true"
45    ${if} ${RunningX64}
46     SetRegView 32
47    ${endif}
48    # check if MiKTeX 2.8 or newer is installed
49    StrCpy $0 0
50    loop32:
51     EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
52     StrCmp $1 "" done32
53     StrCpy $String $1
54     IntOp $0 $0 + 1
55     Goto loop32
56    done32:
57    ${if} $String == "2.9"
58     StrCpy $MiKTeXVersion "2.9"
59     StrCpy $LaTeXName "MiKTeX 2.9"
60    ${endif}
61   ${endif}
62   
63   # check for 64bit MiKTeX
64   ${if} $LaTeXName == ""
65    ${if} ${RunningX64}
66     SetRegView 64
67    ${endif}
68    # check if MiKTeX 2.8 or newer is installed
69    StrCpy $0 0
70    loop64:
71     EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
72     StrCmp $1 "" done64
73     StrCpy $String $1
74     IntOp $0 $0 + 1
75     Goto loop64
76    done64:
77    ${if} $String == "2.9"
78     StrCpy $MiKTeXVersion "2.9"
79     StrCpy $LaTeXName "MiKTeX 2.9"
80    ${endif}
81   ${endif}
82   
83   ${if} $PathLaTeX != ""
84    StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
85   ${else} # check if MiKTeX is installed only for the current user
86    ${if} ${RunningX64}
87     SetRegView 64 # the PATH is in the 64bit registry section
88    ${endif}
89    ReadRegStr $String HKCU "Environment" "Path"
90    StrCpy $Search "miktex"
91    Call LaTeXCheck # function from LyXUtils.nsh
92    ${if} $PathLaTeX != ""
93     StrCpy $MiKTeXUser "HKCU"
94    ${endif}
95   ${endif}
96   ${if} $LaTeXName == "" # check for the MiKTeX version
97    StrCpy $0 0
98    loopB:
99     EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
100     StrCmp $1 "" doneB
101     StrCpy $String $1
102     IntOp $0 $0 + 1
103     Goto loopB
104    doneB:
105    ${if} $String == "2.9"
106     StrCpy $MiKTeXVersion "2.9"
107     StrCpy $LaTeXName "MiKTeX 2.9"
108    ${endif}
109   ${endif}
110   
111   ${if} $PathLaTeX != ""
112    StrCpy $String $PathLaTeX
113    StrCpy $Search "x64" # search if it is 64bit MiKTeX
114    Call StrPoint # Function from LyXUtils.nsh
115    ${if} $Pointer != "-1" # if something was found
116     StrCpy $Is64bit "true"
117    ${endif}
118    StrCpy $LaTeXInstalled "MiKTeX"
119    # on some installations the path ends with a "\" on some not
120    # therefore assure that we remove it if it exists
121    StrCpy $0 $PathLaTeX "" -1
122    ${if} $0 == "\"
123     StrCpy $PathLaTeX "$PathLaTeX" -1 # delete "\"
124    ${endif}
125   ${endif}
126   
127   # test if TeXLive is installed
128   # TeXLive can be installed so that it appears in the PATH variable and/or only as current user.
129   # The safest method is to first check for the PATH because this is independent of the TeXLive version.
130   ${if} ${RunningX64}
131    SetRegView 64 # the PATH is in the 64bit registry section
132   ${endif}
133   ${if} $PathLaTeX == ""
134    ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
135    StrCpy $Search "TeXLive"
136    Call LaTeXCheck # function from LyXUtils.nsh
137   ${endif}
138   # check for the current user Path variable
139   ${if} $PathLaTeX == ""
140    ReadRegStr $String HKCU "Environment" "Path"
141    StrCpy $Search "texlive"
142    StrCpy $2 "TeXLive"
143    Call LaTeXCheck # function from LyXUtils.nsh
144   ${endif}
145   # check if it was installed to the system
146   ${if} ${RunningX64}
147    SetRegView 32 # TeXLive is a 32bit application
148   ${endif}
149   ${if} $PathLaTeX == ""
150    ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "UninstallString"
151    ${if} $String == ""
152     ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "UninstallString"
153    ${endif}
154    ${if} $String != ""
155     StrCpy $String $String -28 # remove '\tlpkg\installer\uninst.bat"'
156     StrCpy $String $String "" 1 # remove the leading quote
157    ${endif}
158    StrCpy $PathLaTeX "$String\bin\win32"
159    # check if the latex.exe exists in the $PathLaTeX folder
160    !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
161    ${if} $5 == "False"
162     StrCpy $PathLaTeX ""
163    ${endif}
164   ${endif}
165   # finally set the name
166   ${if} $PathLaTeX != ""
167   ${andif} $LaTeXName != "MiKTeX 2.9"
168    StrCpy $LaTeXInstalled "TeXLive"
169    ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "DisplayVersion"
170    ${if} $String == ""
171     ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "DisplayVersion"
172    ${endif}
173    ${if} $String != ""
174     StrCpy $LaTeXName "TeXLive $String"
175    ${else}
176     StrCpy $LaTeXName "TeXLive"
177    ${endif}
178   ${endif}
179
180 FunctionEnd
181
182 # ------------------------------
183
184 Function ConfigureMiKTeX
185  # installs the LaTeX class files that are delivered with LyX,
186  # a Perl interpreter for splitindex and pdfcrop
187  # and enable MiKTeX's automatic package installation
188  
189  # install LyX's LaTeX class and style files and a Perl interpreter
190  ${if} $PathLaTeX != ""
191   ${if} $MultiUser.Privileges == "Admin"
192   ${orif} $MultiUser.Privileges == "Power"
193    ${if} $Is64bit == "true"
194     StrCpy $PathLaTeXLocal "$PathLaTeX" -15 # delete "\miktex\bin\x64"
195    ${else}
196     StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
197    ${endif}
198   ${else}
199    StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
200   ${endif}
201
202   # only install the LyX packages if they are not already installed
203   ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
204    # files in Resources\tex
205    SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
206    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
207
208    # refresh MiKTeX's file name database (do this always to assure everything is in place)
209    ${if} $MultiUser.Privileges != "Admin"
210    ${andif} $MultiUser.Privileges != "Power"
211     # call the non-admin version
212     nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
213    ${else}
214     ${if} $MiKTeXUser != "HKCU" # call the admin version
215      nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
216     ${else}
217      nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
218     ${endif}
219    ${endif}
220    Pop $UpdateFNDBReturn # Return value
221   ${endif}
222   
223   # install a Perl interpreter for splitindex and pdfcrop
224   SetOutPath "$INSTDIR\Perl"
225   # recursively copy all files under Perl
226   File /r "${FILES_PERL}\"
227
228   ${endif} # end if $PathLaTeX != ""  
229 FunctionEnd
230
231 # ------------------------------
232
233 Function ConfigureTeXLive
234  # installs the LaTeX class files that are delivered with LyX
235  # (TeXLive comes already with a Perl interpreter.)
236  
237  ${if} $PathLaTeX != ""
238   StrCpy $PathLaTeXLocal "$PathLaTeX" -10 # delete "\bin\win32"
239   
240   # only install the LyX packages if they are not already installed
241   ${ifnot} ${FileExists} "$PathLaTeXLocal\texmf-dist\tex\latex\lyx\broadway.cls"
242    # files in Resources\tex
243    SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
244    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
245    # update TeXLive's package file list
246    ExecWait '$PathLaTeX\texhash'
247   ${endif}
248  ${endif}
249  
250 FunctionEnd