2
/******************************************************************************
3
* MODULE : init_first.cpp
4
* DESCRIPTION: initializations for the first launch of TeXmacs
5
* COPYRIGHT : (C) 1999 Joris van der Hoeven
6
*******************************************************************************
7
* This software falls under the GNU general public license and comes WITHOUT
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11
******************************************************************************/
16
#include "sys_utils.hpp"
17
#include "tex_files.hpp"
18
#include "convert.hpp"
20
/******************************************************************************
21
* Determine installed programs
22
******************************************************************************/
25
init_helper_binaries () {
26
if (exists_in_path ("kpsepath")) {
27
cerr << "TeXmacs] kpsepath works with your TeX distribution\n";
28
set_setting ("KPSEPATH", "true");
31
cerr << "TeXmacs] kpsepath does not work with your TeX distribution\n";
32
set_setting ("KPSEPATH", "false");
35
if (exists_in_path ("kpsewhich")) {
36
cerr << "TeXmacs] kpsewhich works with your TeX distribution\n";
37
set_setting ("KPSEWHICH", "true");
40
cerr << "TeXmacs] kpsewhich does not work with your TeX distribution\n";
41
set_setting ("KPSEWHICH", "false");
44
if (exists_in_path ("mktextfm")) {
45
cerr << "TeXmacs] mktextfm works with your TeX distribution\n";
46
set_setting ("MAKETFM", "mktextfm");
48
else if (exists_in_path ("MakeTeXTFM")) {
49
cerr << "TeXmacs] MakeTeXTFM works with your TeX distribution\n";
50
set_setting ("MAKETFM", "MakeTeXTFM");
53
cerr << "TeXmacs] MakeTeXTFM does not work with your TeX distribution\n";
54
set_setting ("MAKETFM", "false");
57
if (exists_in_path ("mktexpk")) {
58
cerr << "TeXmacs] mktexpk works with your TeX distribution\n";
59
set_setting ("MAKEPK", "mktexpk");
61
else if (exists_in_path ("MakeTeXPK")) {
62
cerr << "TeXmacs] MakeTeXPK works with your TeX distribution\n";
63
set_setting ("MAKEPK", "MakeTeXPK");
66
cerr << "TeXmacs] MakeTeXPK does not work with your TeX distribution\n";
67
set_setting ("MAKEPK", "false");
70
if (exists_in_path ("texhash")) {
71
cerr << "TeXmacs] texhash works with your TeX distribution\n";
72
set_setting ("TEXHASH", "true");
75
cerr << "TeXmacs] texhash does not work with your TeX distribution\n";
76
set_setting ("TEXHASH", "false");
80
/******************************************************************************
81
* Heuristic determination of path with TeX files
82
******************************************************************************/
85
locate (string name, url& p) {
87
(void) name; (void) p;
90
string s= eval_system ("locate " * name);
91
for (i=0; i<N(s); i++)
94
for (j=i-1; j>start; j--)
95
if ((s[j] == '/') || (s[j] == '\\')) break;
96
p= url_system (s (start, j)) | p;
103
search_sub_dirs_sub (url base, url u, url& tfm, url& pk, int status) {
105
if (u[1] == "tfm") status= 1;
106
if (u[1] == "pk") status= 2;
107
search_sub_dirs_sub (base * u[1], u[2], tfm, pk, status);
110
search_sub_dirs_sub (base, u[2], tfm, pk, status);
111
search_sub_dirs_sub (base, u[1], tfm, pk, status);
113
if ((status == 1) || (u == "tfm")) tfm= (base * u) | tfm;
114
if ((status == 2) || (u == "pk" )) pk = (base * u) | pk;
118
search_sub_dirs (url root, url& tfm, url& pk) {
119
url dirs= complete (root * url_wildcard (), "dr");
120
if (!is_none (dirs)) {
121
cerr << "TeXmacs] found TeX directory " << root << "\n";
122
search_sub_dirs_sub (url_here (), dirs, tfm, pk, 0);
127
init_heuristic_tex_paths () {
128
// Not necessary if we can use kpsepath
129
if (get_setting ("KPSEPATH") == "true") {
130
set_setting ("TFM", "");
131
set_setting ("PK", "");
136
url tfm= url_none (), pk= url_none ();
137
string test= eval_system ("locate cmr10.tfm");
139
cerr << "TeXmacs] locate does not work; I will try something else\n";
141
locate (".tfm", tfm);
142
locate (".300pk", pk);
143
locate (".360pk", pk);
144
locate (".400pk", pk);
145
locate (".600pk", pk);
146
locate (".1200pk", pk);
147
if (is_none (tfm)) cerr << "TeXmacs] I could not locate any tfm files\n";
148
else cerr << "TeXmacs] located tfm files in " << tfm << "\n";
149
if (is_none (pk)) cerr << "TeXmacs] I could not locate any pk files\n";
150
else cerr << "TeXmacs] located pk files in " << pk << "\n";
153
// Try some 'standard' directories
155
search_sub_dirs (url_system ("c:\texmf"), tfm, pk);
156
search_sub_dirs (url_system ("d:\texmf"), tfm, pk);
158
search_sub_dirs ("/usr/lib/tetex/fonts", tfm, pk);
159
search_sub_dirs ("/usr/lib/texmf/fonts", tfm, pk);
160
search_sub_dirs ("/var/texfonts", tfm, pk);
161
search_sub_dirs ("/var/tmp/texfonts", tfm, pk);
162
search_sub_dirs ("/usr/TeX/lib/texmf/fonts", tfm, pk);
163
search_sub_dirs ("/usr/local/lib/texmf/fonts", tfm, pk);
164
search_sub_dirs ("/usr/share/texmf/fonts", tfm, pk);
168
if ((is_none (tfm) && (get_env ("TEX_TFM_PATH") == "")) ||
169
(is_none (pk ) && (get_env ("TEX_PK_PATH" ) == ""))) {
171
cerr << "I could not find a TeX system on your system\n";
172
cerr << "If you did install one, please set the system variables\n\n";
173
cerr << "\tTEX_TFM_PATH\n";
174
cerr << "\tTEX_PK_PATH\n\n";
175
cerr << "with the paths where the tfm resp. pk file\n";
176
cerr << "can be found on your system and restart TeXmacs\n";
182
set_setting ("TFM", as_string (expand (factor (tfm))));
183
set_setting ("PK", as_string (expand (factor (pk))));
186
/******************************************************************************
187
* Determine default TeX settings
188
******************************************************************************/
191
try_dpi (int dpi, int test) {
192
cerr << "TeXmacs] Trying to create ecrm10." << test
193
<< "pk from " << dpi << " dpi\n";
194
make_tex_pk ("ecrm10", test, dpi, "localfont");
196
if (!is_none (resolve_pk ("ecrm10." * as_string (test) * "pk"))) {
197
set_setting ("DPI", as_string (dpi));
198
set_setting ("EC", "true");
199
cerr << "TeXmacs] Metafont works with " << dpi << " dpi ec-fonts\n";
203
cerr << "TeXmacs] Trying to create cmr10." << test
204
<< "pk from " << dpi << " dpi\n";
205
make_tex_pk ("cmr10", test, dpi, "localfont");
207
if (!is_none (resolve_pk ("cmr10." * as_string (test) * "pk"))) {
208
set_setting ("DPI", as_string (dpi));
209
cerr << "TeXmacs] Metafont works with " << dpi << " dpi cm-fonts\n";
217
init_default_tex_settings () {
218
set_setting ("DPI", "300");
219
set_setting ("EC", "false");
220
if (get_setting ("MAKEPK") != "false") {
221
if (try_dpi (300, 123));
222
else if (try_dpi (600, 234));
223
else if (try_dpi (1200, 345));
224
else cerr << "TeXmacs] Your mktexpk/MakeTeXPK does not seem to work\n";
228
/******************************************************************************
230
******************************************************************************/
234
url settings_file= "$TEXMACS_HOME_PATH/system/settings.scm";
235
cerr << "Welcome to TeXmacs " TEXMACS_VERSION "\n";
237
cerr << "Since this seems to be the first time you run this\n";
238
cerr << "version of TeXmacs, I will first analyze your system\n";
239
cerr << "in order to set up some TeX paths in the correct way.\n";
240
cerr << "This may take some seconds; the result can be found in\n\n";
241
cerr << "\t" << settings_file << "\n\n";
244
set_setting ("VERSION", TEXMACS_VERSION);
245
init_helper_binaries ();
246
init_heuristic_tex_paths ();
247
init_default_tex_settings ();
249
string s= scheme_tree_to_block (texmacs_settings);
250
if (save_string (settings_file, s) || load_string (settings_file, s)) {
252
cerr << "I could not save or reload the file\n\n";
253
cerr << "\t" << settings_file << "\n\n";
254
cerr << "Please give me full access control over this file and\n";
255
cerr << "rerun 'TeXmacs'.\n";
261
cerr << "Installation completed successfully !\n";
262
cerr << "I will now start up the editor\n";