Back to index

texmacs  1.0.7.15
tex_init.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : tex_init.cpp
00004 * DESCRIPTION: initializations for using Metafont
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "boot.hpp"
00013 #include "file.hpp"
00014 #include "path.hpp"
00015 #include "sys_utils.hpp"
00016 #include "convert.hpp"
00017 #include "tex_files.hpp"
00018 
00019 /******************************************************************************
00020 * Determine installed programs
00021 ******************************************************************************/
00022 
00023 static void
00024 init_helper_binaries () {
00025   if (exists_in_path ("kpsepath")) {
00026     cerr << "TeXmacs] kpsepath works with your TeX distribution\n";
00027     set_setting ("KPSEPATH", "true");
00028   }
00029   else set_setting ("KPSEPATH", "false");
00030 
00031   if (exists_in_path ("kpsewhich")) {
00032     cerr << "TeXmacs] kpsewhich works with your TeX distribution\n";
00033     set_setting ("KPSEWHICH", "true");
00034   }
00035   else set_setting ("KPSEWHICH", "false");
00036 
00037   if (exists_in_path ("mktextfm")) {       
00038    cerr << "TeXmacs] mktextfm works with your TeX distribution\n";     
00039    set_setting ("MAKETFM", "mktextfm");    
00040   }     
00041   else if (exists_in_path ("MakeTeXTFM")) {       
00042     cerr << "TeXmacs] MakeTeXTFM works with your TeX distribution\n";         
00043     set_setting ("MAKETFM", "MakeTeXTFM");        
00044   }     
00045   else if (exists_in_path ("maketfm")){    
00046     cerr << "TeXmacs] maketfm works with your TeX distribution\n";     
00047     set_setting ("MAKETFM", "maketfm");    
00048   }     
00049   else set_setting ("MAKETFM", "false");
00050   
00051   if (exists_in_path ("mktexpk")) {        
00052     cerr << "TeXmacs] mktexpk works with your TeX distribution\n";     
00053     set_setting ("MAKEPK", "mktexpk");     
00054   }     
00055   else if (exists_in_path ("MakeTeXPK")) {        
00056     cerr << "TeXmacs] MakeTeXPK works with your TeX distribution\n";   
00057     set_setting ("MAKEPK", "MakeTeXPK");   
00058   }     
00059   else if (exists_in_path ("makepk")){     
00060     cerr << "TeXmacs] makepk works with your TeX distribution\n";      
00061     set_setting ("MAKEPK", "makepk");      
00062   }     
00063   else set_setting ("MAKEPK", "false");
00064 
00065   if (exists_in_path ("texhash")) {        
00066     cerr << "TeXmacs] texhash works with your TeX distribution\n";     
00067     set_setting ("TEXHASH", "true");       
00068   }     
00069   else set_setting ("TEXHASH", "false");
00070   
00071   set_setting ("DPI", "600");
00072 }
00073 
00074 /******************************************************************************
00075 * Heuristic determination of path with TeX files
00076 ******************************************************************************/
00077 
00078 static void
00079 search_sub_dirs_sub (url base, url u, url& tfm, url& pk, url& pfb, int status) {
00080   if (is_concat (u)) {
00081     if (u[1] == "tfm") status= 1;
00082     if (u[1] == "pk" ) status= 2;
00083     if (u[1] == "pfb" || u[1] == "type1") status= 3;
00084     search_sub_dirs_sub (base * u[1], u[2], tfm, pk, pfb, status);
00085   }
00086   if (is_or (u)) {
00087     search_sub_dirs_sub (base, u[2], tfm, pk, pfb, status);
00088     search_sub_dirs_sub (base, u[1], tfm, pk, pfb, status);
00089   }
00090   if ((status == 1) || (u == "tfm")) tfm= (base * u) | tfm;
00091   if ((status == 2) || (u == "pk" )) pk = (base * u) | pk;
00092   if ((status == 3) || (u == "pfb") || (u == "pfb")) pfb = (base * u) | pfb;
00093 }
00094 
00095 static void
00096 search_sub_dirs (url root, url& tfm, url& pk, url& pfb) {
00097   url dirs= complete (root * url_wildcard (), "dr");
00098   if (!is_none (dirs)) {
00099     cerr << "TeXmacs] found TeX directory " << root << "\n";
00100     search_sub_dirs_sub (url_here (), dirs, tfm, pk, pfb, 0);
00101   }
00102 }
00103 
00104 #ifdef OS_WIN32
00105 static url
00106 search_sub_dirs (url root) {
00107   url dirs= complete (root * url_wildcard (), "dr");
00108   return expand (dirs);
00109 }
00110 #endif
00111 
00112 static void
00113 init_heuristic_tex_paths () {
00114   url tfm= url_none (), pk= url_none (), pfb= url_none ();
00115 
00116   // Try some 'standard' directories
00117 #ifdef OS_WIN32
00118   tfm= search_sub_dirs ("$TEX_HOME/fonts/tfm");
00119   pk = search_sub_dirs ("$TEX_HOME/fonts/pk");
00120   pfb= search_sub_dirs ("$TEX_HOME/fonts/type1");
00121 #else
00122   search_sub_dirs ("/opt/local/share/texmf-texlive-dist/fonts", tfm, pk, pfb);
00123   search_sub_dirs ("/usr/lib/tetex/fonts", tfm, pk, pfb);
00124   search_sub_dirs ("/usr/lib/texmf/fonts", tfm, pk, pfb);
00125   search_sub_dirs ("/usr/local/lib/texmf/fonts", tfm, pk, pfb);
00126   search_sub_dirs ("/usr/share/texmf/fonts", tfm, pk, pfb);
00127   search_sub_dirs ("/usr/TeX/lib/texmf/fonts", tfm, pk, pfb);
00128   search_sub_dirs ("/var/texfonts", tfm, pk, pfb);
00129   search_sub_dirs ("/var/tmp/texfonts", tfm, pk, pfb);
00130 #endif
00131 
00132 #ifdef OS_WIN32
00133   set_setting ("TFM", as_string (tfm));
00134   set_setting ("PK" , as_string (pk ));
00135   set_setting ("PFB", as_string (pfb));
00136 #else
00137   set_setting ("TFM", as_string (expand (factor (tfm))));
00138   set_setting ("PK" , as_string (expand (factor (pk ))));
00139   set_setting ("PFB", as_string (expand (factor (pfb))));
00140 #endif
00141 }
00142 
00143 /******************************************************************************
00144 * Setting up and initializing TeX fonts
00145 ******************************************************************************/
00146 
00147 void
00148 setup_tex () {
00149   remove ("$TEXMACS_HOME_PATH/fonts/font-index.scm");
00150   init_helper_binaries ();
00151   init_heuristic_tex_paths ();
00152 }
00153 
00154 void
00155 init_tex () {
00156   reset_tfm_path (false);
00157   reset_pk_path (false);
00158   reset_pfb_path ();
00159 }