home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmtfe30.zip / source.zip / source / texfe.e < prev    next >
Text File  |  2000-05-29  |  86KB  |  2,449 lines

  1. /**************************************************************************/
  2. /*                                                                        */
  3. /* What's it called: EPM TeX Front End (texfe.e)                          */   
  4. /*                                                                        */
  5. /*                                                                        */
  6. /* What does it do:  The E source code for the EPM TeX Front End          */
  7. /*                                                                        */
  8. /* Who and When:     Originally written as 'EPMTeX' by John Hacker,       */
  9. /*                   Rodney Korte, Thorsten Domsalla and Joachim Koenen,  */
  10. /*                   1/1993-10/1995;                                      */
  11. /*                   this version by Walter Schmidt, 05/2000,             */
  12. /*                   with contributions by Wonkoo Kim.                    */
  13. /*                                                                        */
  14. /* Copyright (c) Walter Schmidt 1997--2000                                */
  15. /*                                                                        */
  16. /**************************************************************************/
  17.  
  18. /*
  19.  
  20. Version 3.0
  21.  
  22.     * changed default VTeX options with respect to VTeX 7.x
  23.     
  24.     * optionally bind bracket matching facility to Ctrl-a,
  25.     controlled by const WANT_CTRLA
  26.  
  27.     * quick keys are always active; 
  28.     the list of "auxiliary" file types is no longer needed.
  29.     
  30.     * Pro version:  TeX menu is never disabled
  31.     
  32.  
  33. Version 2.6
  34.  
  35.     * name of conf. variable "my_vtex" changed to "vtex".
  36.     
  37.     * menu item for "quick" VTeX added.
  38.     
  39.     * defproc tex_editsetting; one common procedure for editing
  40.     the TeX settings; additional button to restore the default 
  41.     settings
  42.     
  43.     * Default settings are defined as const's now.
  44.     
  45.     * With the TeX Front End for VTeX all settings (except for
  46.     the user commands) can be edited interactively.
  47.     
  48.  
  49. Version 2.5
  50.  
  51.     * Bug fix:  Folders will be opened via SysSetObjectData instead of
  52.     SysOpenObject; see the file tfefm.cmd.
  53.     
  54.     * Bug fix:  tex_cd won't fail any more when changing to the root
  55.     directory of a drive.
  56.     
  57.     * menu item for pdf preview added
  58.     
  59.     * menu shortcut for dvips changed to v
  60.     
  61.     * v2.5 should understand VTeX's error messages, too
  62.     
  63.     * new configuration variable:  my_vtex:  dvi stuff won't be
  64.     included, when this variable is defined.  TeX and TeX/PS will call
  65.     VTEX.EXE immediately and pass the (unchanged) format name to it; the
  66.     configuration keywords PDF_OPTIONS and PS_OPTIONS determine the
  67.     further options to be passed to VTEX.EXE.
  68.  
  69.  
  70. Version 2.4
  71.  
  72.     * Path of master file should be recognized properly now.
  73.  
  74.     * ADVANCED marking mode is no longer required for TeXing a marked
  75.     region; now this works with CHAR marks, too;
  76.  
  77.     * New way to call TeX and/or dvips; tfetexps.cmd is no longer
  78.     required, and the window will stay open in case of dvips errors.
  79.  
  80.     * The commands for running the various TeX formats as well as the
  81.     dvips command can be of type .exe or .cmd; the extension need _not_
  82.     be specified.
  83.  
  84.     * dvips options are now placed before the .dvi filename
  85.  
  86.     * The name of the dvi file is passed to dvips WITHOUT the extension
  87.     '.dvi' .
  88.  
  89.     * Enhanced syntax assist:  expand \[ and \(
  90.  
  91.     * Quick key' and menu shortcut for dvips added.
  92.     
  93.     * The menu item PRINT is suppressed if there is no command defined
  94.     for it.
  95.  
  96.     * It seemed as if setTexKeySets() and setTexHilite() would not
  97.     always be excuted when a file name was passed via the command line
  98.     or by 'drag and drop,' so we call them once more at definit.  This
  99.     affects the texfe module only, not the Pro version.
  100.     
  101.     * const WANT_INCLUDEONLY_SUPPORT (experimental feature, see the file
  102.     'compile.txt')
  103.  
  104.     
  105. Version 2.2
  106.  
  107.     * Default value of LATEX_SYNTAX_INDENT is now 2
  108.     
  109.     * Improved syntax assist:  Arguments of environments may appear on
  110.     the same line.  Arbitrary long environment names are recognized.
  111.     Reasonable handling of the 'verbatim' and 'macrocode' environments.
  112.     (See file texfek.e)
  113.     
  114.     * Optimized code for processing the EPMTeX accelerator keys; approx.
  115.     1kB smaller than the previous version.  (See file texfed.e)
  116.  
  117.  
  118. Version 2.1
  119.  
  120.     * tex_file_in_ring() rewritten; files differing in path only 
  121.     should now be handled properly.
  122.     
  123.     * Call 'TeXMenuEnable' once more, because the TeX menu would be
  124.     enabled erroneously under certain circumstances.  There is, however,
  125.     no complete solution to this problem.
  126.     
  127.     * Fixed the menu item "Menu always on', which would not display its
  128.     current setting.
  129.     
  130.     
  131. Version 2.0
  132.  
  133.     * The TeX menu is now provided with the module, too.
  134.     
  135.     * The default format can be changed via the settings menu; manual
  136.     format select is no longer provided.
  137.     
  138.     * Removed the menu item "Delete log file".
  139.  
  140.     * Bug fix: Customized <enter> key would not be honored
  141.     
  142.     * Bug fix: \end{...} would not be properly indented
  143.     
  144.     * New optional feature: Simple automatic indentation within LaTeX
  145.     environmemts, controlled by const LATEX_SYNTAX_INDENT.
  146.     
  147.     * Syntax assist (expansion): \fo -> \footnote{}
  148.     
  149.     * "Menu always on" can be toggled via the TeX menu only.
  150.     
  151.     * const EXTENDED_LATEX_ASSIST = 1 will include Juan J.G.Ripoll's
  152.     LaTeX auto-indentation package.
  153.     
  154.     * strip leading and trailing spaces from settings values which are 
  155.     entered interactively
  156.  
  157.  
  158. Version 1.1
  159.  
  160.     * Bug fix:  Menu item "Master file support" was broken.  (Only vith
  161.     v1.1 as of 1998-01-07.)
  162.     
  163.     * Added "Cancel" buttons to options entry box and to "process 
  164.     marked region" dialog box.
  165.     
  166.     * TeXing a marked region is now possible with plain TeX, too.  The
  167.     end of the header is indicated by "%**end of header"
  168.  
  169.     * "Locate Next Error" and "View Log File" will always refer to the 
  170.     log file of the *latest* TeX run.  The name of the log file is
  171.     memorized from one EPM invocation to the next and will be displayed 
  172.     while definit.
  173.  
  174.     * "Locate Next Error" will again draw a circle around the location
  175.     of the error.  I have found a reliable (!) method to do so.
  176.  
  177.     * "Locate next error" will at least display the name of the TeX
  178.     input file an error message refers to, if line number of error is
  179.     not indicated in the transcript file.
  180.  
  181.     * "View Log File" will reset the error browsing facility when called
  182.     from within the log file.
  183.     
  184.     * rewrote tex_more_errors(), the old one was too obscure ...
  185.     
  186.     * fixed a bug which caused the first line of the log file to be 
  187.     displayed instead of the recently found error, if the Log action was
  188.     triggered after the last error in the file had been processed.
  189.  
  190.     * The TeX command connected with a certain format can now be an exe
  191.     file, too.
  192.  
  193.     * Syntax highlighting is checked while defload; file types DTX and
  194.     FDD are never highlighted.
  195.     
  196.     * *Each* occurence of %**N or %**F in the external commands will now
  197.     be replaced with the filename.
  198.     
  199.     * Syntax assist: Fixed a bug which prevented the description
  200.     environment from being recognized (file texfek.e).
  201.     
  202.     * Syntax assist (expansion):
  203.     New :    \la -> \label{},   \re -> \ref{}
  204.     Removed: \hs -> \hspace{},  \vs -> \vspace{}
  205.  
  206.     * Preview, user commands etc.  will no longer change into master
  207.     file.  However, they cannot be executed, if master file does not
  208.     exist, regardless of the associated file type.
  209.  
  210.     * In case an external command is undefined, the corresponding menu
  211.     item or toolbar button will display an appropriate error message.
  212.     
  213.     * Replaced various error messages with pop-up windows for better 
  214.     information.
  215.     
  216.     * Pro version: "Shell" and "Folder" added to the "Command" and 
  217.     "File" submenus, instead of creating an "OS/2" submenu.  Applies 
  218.     only if STD_MENU_NAME is undefined, i.e. the standard menu is used.
  219.     
  220.     * Code optimization; no more unnecessary directory switching etc.
  221.  
  222.     * Many changes to the messages in texfeen.e
  223.  
  224.     * German version
  225.     
  226.     * rewrote the settings menu due to NLS support
  227.  
  228.  
  229. Version 1.0
  230.  
  231.     * TeX a marked region of the current file
  232.  
  233.     * Various changes to tex_extract_filename and tex_find_errors. 
  234.     Should now handle *all* TeX error messages!  If location of error 
  235.     cannot be determined, the log file will be displayed.
  236.  
  237.     * "View LOG File" now goes to the line of the last error which has 
  238.     been located before; the parsing routines will only be initialized, 
  239.     if there are no more errors or the log file is not found in the 
  240.     ring.
  241.  
  242.     * The log file being viewed is read-only.
  243.  
  244.     * Fixed one more error affecting handling of filenames without 
  245.     extension, in the procedure tex_file_in_ring.
  246.  
  247.     * Removed defc tex_warning
  248.     
  249.     * In case a specified master file does not exist, the current action
  250.     will be stopped without querying "Continue processing ... ?".
  251.  
  252.     * Fixed the TeX/PS action, which used to fail with file types other
  253.     than '.TEX'.
  254.     
  255.     * The name of the dvips executable will be determined from the INI 
  256.     file.  The default is 'dvips', as before.
  257.  
  258.     * The debug level is no longer saved in the INI file.  Each EPM 
  259.     session will start with TeX_debug = 0 .
  260.  
  261.     
  262. Version 0.96
  263.     
  264.     * File types, highlighting etc.  are configured via a menu.  The
  265.     EPM commands introduced with v0.92 have been removed.
  266.  
  267.     * The procedure tex_locate_error will no longer run into an endless
  268.     loop , if the TeX error does not refer to a line number, e.g.  with
  269.     "runaway argument".  Furthermore, it will move the cursor only; no 
  270.     mark will be set.
  271.  
  272.     * Changes to the syntax assist facility:  Completion of environments
  273.     and keywords will always be active with TeX documents/styles.  The
  274.     new command tex_keys will toggle the behaviour of the accelerator 
  275.     keys only.  The command tex_syntaxassist has been abandoned. 
  276.     New expansion: "\fr " -> "\frac{}{}"
  277.     Removed:       "\it " -> "\item "
  278.  
  279.     * Restored the "Quick Keys":
  280.     TeX               : Ctrl F9
  281.     TeX/PS            : Ctrl F10
  282.     locate next error : Ctlr F11
  283.     view log file     : Ctrl F12
  284.     This was the only way to get the same sequence as in the toolbar, so
  285.     it is necessarily different from EPMTeX's key assignments.
  286.  
  287.     * Restored the EPMTeX accelerator keys
  288.  
  289.  
  290. Changes from epmtex 3.1a to TeX Front End 0.92 (the first public
  291. version):
  292.  
  293.     Toolbar:
  294.  
  295.     * The standard version has no pull-down menus any more.  Instead it
  296.     is controlled via the toolbar.  This is because the menu identifiers
  297.     from different modules may collide.  With the Pro version one has
  298.     the source code available and can ensure unique menu identifiers.
  299.     
  300.     Files:
  301.  
  302.     * TeX documents are no longer required to have the extension .TEX
  303.  
  304.     * Since TeXing is no longer restricted to .TEX files, there are now
  305.     three different lists of 'file extensions to associate with TeX':
  306.     One for TeX documents, another one for style files, and a third one 
  307.     for auxiliary files.  The syntax assist is available with the 
  308.     documents and the style files, and the auxiliary files are those 
  309.     which provide syntax highlighting and the quick keys, too.  The TeX 
  310.     menu of the Pro version is enabled with file types from any list.
  311.     
  312.     Formats:
  313.  
  314.     * The default format is 'latex', unless there is a different 
  315.     specification in the configuration file.
  316.  
  317.     * Each format is called through its own batch file, so that the TeX
  318.     options and the environment settings can be specified individually.
  319.     
  320.     Configuration, external programs:
  321.  
  322.     * The master file support is now toggled via the menu resp.  the
  323.     toolbar.
  324.     
  325.     * The program epmtex.exe has disappeared.  Instead, some of the
  326.     settings are controlled via EPM commands; others are defined in a
  327.     text file TFE.CFG and transferred to EPM.INI by a configuration
  328.     script named TFCONFIG.CMD, which is *not* run from within the EPM.
  329.     The entries in the configuration file specify EPM commands, so that
  330.     one can run external programs (start /n program), EPM REXX programs
  331.     (rx program) or built-in EPM commands (sayerror ...).
  332.  
  333.     * Options may be passed interactively to external programs; see the 
  334.     documentation.  Thus e.g. the printer driver can now be told to 
  335.     process a certain range of pages only.
  336.  
  337.     * The passing of the filename to an external command has been 
  338.     changed:  Within the "executable file name" (i.e.  the command
  339.     line) the following substitutions will occur:
  340.  
  341.       %**N  ->  the filename without extension
  342.       %**F  ->  the filename incl. extension
  343.  
  344.     This syntax is similar to the WPS, and it should cover all possible
  345.     calling schemes of external programs.  In case none of the above
  346.     strings is present, the filename will *not* be passed to the
  347.     program.
  348.     
  349.     New features:
  350.  
  351.     * The commands for previewimg, printing, dvips and the user commands
  352.     will switch to the master file before running.
  353.     
  354.     * New menu items resp. toolbar buttons:  "Folder" opens the
  355.     directory of the current file as a WPS folder.  "Command Prompt"
  356.     creates an OS/2 shell window in the directory of the current file.
  357.  
  358.     * New menu items for dvips and Postscript viewing (Ghostview) have
  359.     been added.  (In case your *printer* supports Postscript, then you
  360.     just have to specify dvips to be used as the printer driver, too.)
  361.  
  362.     * There is a new menu item named TeX/PS.  It will run TeX and dvips
  363.     in sequence, so that you need not call dvips explicitly.  This is 
  364.     useful if you know that you will have to preview your document via
  365.     Postscript, because it contains Type 1 fonts or other Postscript
  366.     material.
  367.  
  368.     * The syntax assist facility will recognize more expansions: 
  369.       "equ " -> "equation" 
  370.       "eqn " -> "eqnarray"
  371.       "\hs " -> "\hspace"
  372.       "\vs " -> "\vspace"
  373.  
  374.     Removed features:
  375.  
  376.     * The 'TeX margins' have been removed due to their somewhat obscure
  377.     interaction with the `general' margins setting:  Switching the TeX
  378.     margins ON does not immediately affect the current file, but when
  379.     you open and close the settings notebook while the TeX margins are
  380.     active, then they will be saved, too, and become the 'general'
  381.     default for all file types.  (I do understand what happens here,
  382.     but what about users who are interested in writing texts and not in
  383.     the EPM internals?)
  384.     
  385.     * The 'user defined formats' have disappeared.  To my opinion it is 
  386.     difficult to understand why there are two different ways of defining
  387.     the format to be used: The 'automatic format selection' and the 
  388.     'user formats'.
  389.  
  390.     * The following features have also been removed:
  391.       Orientation
  392.       Resolving of references to environment variables (Will perhaps 
  393.         return in a later version)
  394.       Unix style directory separators
  395.       The menu item 'Remove DVI file'
  396.       The option 'Auto save' (i.e. it is now always on)
  397.       The option 'Auto log delete' (i.e. it is now always off)
  398.       The 'Quick keys' (they may return in a later version)
  399.       The 'Accelerator keys', except for '{', '$' and Ctrl-x,
  400.         which are now included in the 'Syntax Assist' option.
  401.       The TeX tabs
  402.       The TeX margins (see above)
  403.       The user formats (see above)
  404.       (My policy was: Keep it small and simple!)
  405.       
  406.     Bug fixes:
  407.  
  408.     * Dependent files will be recognized when given as "\input{file}",
  409.     too.  Formerly only "\input file" and "\include{file}" were allowed.
  410.  
  411.     * Dependent files will no lomger be checked for modification if the
  412.     \input or \include commands are commented out.
  413.     
  414.     * A user defined mouse pointer will no longer be overwritten by the 
  415.     TeX module.
  416.     
  417.     * 'Locate Next Error' has been made much more robust and handles
  418.     arbitrary filenames now.
  419.  
  420.     * The initialization code is no longer executed multiple times.
  421.     
  422.     Source code:
  423.     
  424.     * When compiling the Pro version, the TeX module is now included
  425.     into EPM.EX so that no separate .ex file must be loaded at startup 
  426.     time.
  427.  
  428.     * All messages are defined in a separate file so that support for
  429.     different languages will be possible in the future.
  430.     
  431.     * Cleaned up the source code, removed unused universal variables
  432.     etc.
  433.  
  434.  
  435. Known bugs and deficiencies:
  436.  
  437.     * You cannot TeX a file which has no `type'.
  438.  
  439.     * The LaTeX command \includeonly should be honored when master file
  440.     support is on.
  441.     
  442.     * Only one simgle \include or \input command per line is recognized.
  443.     
  444.     * A drive letter in a '%master' statement must be followed by an 
  445.     absolute path.
  446.     
  447.     * A drive letter in a '%master' statement is not recognized at all,
  448.     if there is no colon after the keyword 'master'.
  449.  
  450.     * A folder opened via tex_fm cannot be closed through the window
  451.     list.
  452.     
  453.     * The TeX menu is sometimes enabled erroneously, e.g., when a new 
  454.     module is loaded which adds its own submenu.
  455.  
  456.     * You cannot jump back to the _previous_ error.
  457.  
  458.     * You cannot request the window of a command to stay open after
  459.     completion, because the `start' command has no such option.  This
  460.     would sometimes be convenient, so as to see whether a command has
  461.     terminated normally or with an error message.
  462.     
  463.     * You cannot request a user command to check whether the document 
  464.     and the dependent files need to be saved before the command is 
  465.     executed.
  466. */
  467.  
  468.  
  469.  
  470. /*********************************/
  471. /*                               */
  472. /*  We need EPM 6.03b or later   */
  473. /*                               */
  474. /*********************************/
  475.  
  476. compile if EVERSION < '6.03b'
  477.   *** Error: EPM version 6.03b required
  478. compile endif
  479.  
  480.  
  481. /******************************/
  482. /*                            */
  483. /*  Standard or Pro version   */
  484. /*                            */
  485. /******************************/
  486.  
  487. compile if not defined(SMALL) -- being separately compiled
  488.   const TEXFEPRO = 0
  489. compile else                  -- integrated "Pro(fessional)" version
  490.   const TEXFEPRO = 1
  491. compile endif
  492.  
  493.  
  494. /*
  495. ┌────────────────────────────────────────────────────────────────────────────┐
  496. │  Include the standard stuff we need  when we are compiling separately      │
  497. │  from epm.ex.                                                              │
  498. └────────────────────────────────────────────────────────────────────────────┘
  499. */
  500.  
  501. compile if not defined(SMALL)  -- Being compiled separately
  502.   include 'stdconst.e'
  503.   include 'colors.e'
  504.   define INCLUDING_FILE = 'TEXFE.E'
  505.   tryinclude 'MYCNF.E'
  506.   compile if not defined(SITE_CONFIG)
  507.     const SITE_CONFIG = 'SITECNF.E'
  508.   compile endif
  509.   compile if SITE_CONFIG
  510.     tryinclude SITE_CONFIG
  511.   compile endif
  512.   compile if not defined(NLS_LANGUAGE)
  513.     const NLS_LANGUAGE = 'ENGLISH'
  514.   compile endif
  515. compile endif -- SMALL
  516.  
  517.  
  518. /**************************************************/
  519. /*                                                */
  520. /* Default settings of the compile-time variables */
  521. /*                                                */
  522. /**************************************************/
  523.  
  524. compile if not defined(WANT_TEX_MENU) -- may have been defined in MYCNF.E
  525.   define WANT_TEX_MENU = 1  -- default is to include the menu
  526. compile endif
  527.  
  528. compile if not defined(EXTENDED_LATEX_ASSIST)
  529.   define EXTENDED_LATEX_ASSIST = 0
  530. compile endif
  531.  
  532. compile if not defined(WANT_INCLUDEONLY_SUPPORT)
  533.   define WANT_INCLUDEONLY_SUPPORT = 0
  534. compile endif
  535.  
  536. compile if EXTENDED_LATEX_ASSIST and (defined (vtex))
  537.   *** Sorry, you cannot enable EXTENDED_LATEX_ASSIST in conjunction with VTeX
  538. compile endif  
  539.  
  540. compile if not defined(WANT_CTRLA)
  541.   define WANT_CTRLA = 0
  542. compile endif
  543.  
  544.  
  545.  
  546. /*******************/
  547. /*                 */
  548. /*  Version info   */
  549. /*                 */
  550. /*******************/
  551.  
  552. compile if defined (vtex)
  553.   define PrimVersion = '3.0-V'
  554. compile else  
  555.   define PrimVersion = '3.0'
  556. compile endif  
  557.  
  558. const
  559. compile if TEXFEPRO
  560.   TEXFE_VERSION = PrimVersion || ' Pro'
  561. compile else
  562.   TEXFE_VERSION = PrimVersion
  563. compile endif /* TEXFEPRO */
  564.   TEXFE_COPYRIGHT = '(C) Walter Schmidt 1997-2000'
  565.  
  566. /* Within EPM.INI this application identifies itself as EPMTFE */
  567. TEX_APP = 'EPMTFE'
  568.  
  569.  
  570. /************************/
  571. /*                      */
  572. /*   Default settings   */
  573. /*                      */
  574. /************************/
  575.  
  576. const 
  577.   TEX_STYLETYPES_D = 'STY'
  578.   TEX_DOCTYPES_D = 'TEX'
  579.   TEX_DEFAULT_FORMAT_D = 'latex'
  580.   TEX_PDF_OPTIONS_D = '-ov -pu0 -ox -ob2 -ofpdf -$p(h=29.7cm,w=21cm,f=f,t=f,g=f,!'
  581.   TEX_PS_OPTIONS_D = '-ov -pu0 -ofps -$s(g=a'
  582.   TEX_VIEWPDF_D = 'start /n /f c:\gstools\gsview\gvpm.exe %**N.pdf'
  583.   TEX_VIEWPS_D = 'start /n /f c:\gstools\gsview\gvpm.exe %**N.ps'
  584.   TEX_DVIPS_EXEC_D = 'dvips'
  585.  
  586.  
  587. /************************/
  588. /*                      */
  589. /* Include NLS support  */
  590. /*                      */
  591. /************************/
  592.  
  593. /* only German and English currently available */
  594. compile if NLS_LANGUAGE = 'DEUTSCH'
  595.    include 'texfede.e'
  596. compile else
  597.    include 'texfeen.e'
  598. compile endif
  599.  
  600.  
  601. /***************/
  602. /*             */
  603. /*   definit   */
  604. /*             */
  605. /***************/
  606.  
  607. definit  -- called once at startup time
  608.    universal app_hini,
  609.              tex_debug,
  610.              tex_log_file_name,
  611.              tex_log_file_line,
  612.              tex_log_file_curr
  613. compile if EXTENDED_LATEX_ASSIST
  614.    universal TeX_Margin
  615. compile endif
  616.  
  617. -- we initialize the information in the INI file, if necessary
  618.     
  619.    answer = queryprofile(app_hini, TEX_APP, 'VERSION')
  620.    if answer <> TEXFE_VERSION then
  621.       -- the database might have been changed,
  622.       -- so we must check some of the settings:
  623.       answer = queryprofile(app_hini, TEX_APP, 'STYLETYPES')
  624.       if answer = '' then
  625.          call setprofile(app_hini, TEX_APP, 'STYLETYPES', TEX_STYLETYPES_D)
  626.       endif
  627.       answer = queryprofile(app_hini, TEX_APP, 'DOCTYPES')
  628.       if answer = '' then
  629.          call setprofile(app_hini, TEX_APP, 'DOCTYPES', TEX_DOCTYPES_D)
  630.       endif
  631.       answer = queryprofile(app_hini, TEX_APP, 'DEFAULT_FORMAT')
  632.       if answer = '' then
  633.          call setprofile(app_hini, TEX_APP, 'DEFAULT_FORMAT', TEX_DEFAULT_FORMAT_D)
  634.       endif
  635. compile if defined (vtex)
  636.       answer = queryprofile(app_hini, TEX_APP, 'PDF_OPTIONS')
  637.       if answer = '' then
  638.          call setprofile(app_hini, TEX_APP, 'PDF_OPTIONS', TEX_PDF_OPTIONS_D)
  639.       endif
  640.       answer = queryprofile(app_hini, TEX_APP, 'PS_OPTIONS')
  641.       if answer = '' then
  642.          call setprofile(app_hini, TEX_APP, 'PS_OPTIONS', TEX_PS_OPTIONS_D)
  643.       endif
  644.       answer = queryprofile(app_hini, TEX_APP, 'VIEWPDF_CMD')
  645.       if answer = '' then
  646.          call setprofile(app_hini, TEX_APP, 'VIEWPDF_CMD', TEX_VIEWPDF_D)
  647.       endif
  648.       answer = queryprofile(app_hini, TEX_APP, 'VIEWPS_CMD')
  649.       if answer = '' then
  650.          call setprofile(app_hini, TEX_APP, 'VIEWPS_CMD', TEX_VIEWPS_D)
  651.       endif
  652. compile else
  653.       answer = queryprofile(app_hini, TEX_APP, 'DVIPS_EXEC')
  654.       if answer = '' then
  655.          call setprofile(app_hini, TEX_APP, 'DVIPS_EXEC', TEX_DVIPS_EXEC_D)
  656.       endif
  657. compile endif      
  658.       -- leave an 'ok' mark:
  659.       call setprofile(app_hini, TEX_APP, 'VERSION', TEXFE_VERSION)
  660.    endif -- VERSION
  661.  
  662. compile if WANT_TEX_MENU
  663.    'PostMe BuildTexMenu'    -- delay creating menu until after the definit
  664. compile endif
  665.  
  666. -- we initialize the debug level
  667.    tex_debug = 0
  668.  
  669. -- we initialize log file processing
  670.    tex_log_file_name = queryprofile(app_hini, TEX_APP, 'LOGFILE')
  671.    if tex_log_file_name <> '' then
  672.       sayerror TEX_LOGINIT_STRING||tex_log_file_name
  673.    endif
  674.    tex_log_file_line = 1
  675.    tex_log_file_curr = 1
  676.  
  677. -- we initialize the TeX line width
  678. compile if EXTENDED_LATEX_ASSIST
  679.    TeX_Margin = queryprofile(app_hini, TEX_APP, 'MARGIN')
  680.    if TeX_Margin = '' then
  681.       TeX_Margin = 72
  682.       call setprofile(app_hini, TEX_APP, 'MARGIN', 72)
  683.    endif
  684. compile endif
  685.  
  686. -- initialize those keys which are always to be defined
  687.    def C_F9=  'tex'
  688.    def C_F10= 'texps'
  689. compile if not defined (vtex)
  690.    def C_v=   'tex_dvips'
  691. compile endif
  692.    def C_F11= 'tex_locate_error'
  693.    def C_F12= 'tex_view_log'
  694. compile if WANT_CTRLA
  695.    def c_a call passist()
  696. compile endif
  697.  
  698. -- initialize type-dependent keys and syntax hilite (module only);
  699. -- it seems as if 1st file is loaded before texfe.ex (???)
  700. compile if not TEXFEPRO
  701.    call setTexKeySets()
  702.    call setTexHilite()
  703. compile endif
  704.  
  705.  
  706. /*****************/
  707. /*               */
  708. /*   defselect   */
  709. /*               */
  710. /*****************/
  711.  
  712. defselect -- called at startup time and when switching files
  713.     -- load any requested keysets and enable syntax expansion
  714.     call setTexKeySets()
  715.     
  716. compile if EXTENDED_LATEX_ASSIST
  717.     -- set margins to infinity, so as not to collide with TeX margins,
  718.     -- when a TeX document or style file is edited
  719.     call setTeXMargins()
  720. compile endif
  721.  
  722.  
  723. /***************/
  724. /*             */
  725. /*   defload   */
  726. /*             */
  727. /***************/
  728.  
  729. defload -- called when loading a file
  730.    -- set hiliting if TeX file loaded
  731.    call setTexHilite()
  732.  
  733.  
  734. /**********************************************************/
  735. /*                                                        */
  736. /*  include the key set and the syntax assist functions   */
  737. /*                                                        */
  738. /**********************************************************/
  739.  
  740. compile if EXTENDED_LATEX_ASSIST
  741.   include 'emacs.e'
  742.   include 'xtexfek.e'
  743. compile else
  744.   include 'texfek.e'
  745. compile endif
  746.  
  747.  
  748. /****************************/
  749. /*                          */
  750. /*  Define TeX menu system  */
  751. /*                          */
  752. /****************************/
  753.  
  754. compile if WANT_TEX_MENU
  755.  
  756. defc BuildTexMenu
  757.     universal  defaultmenu,
  758.                app_hini
  759.  
  760. -- load in required environment information to build menu system
  761.     TEX_USER1_MENU_TEXT = queryprofile( app_hini, TEX_APP, 'USER1_MENU_TEXT')
  762.     TEX_USER1__MSG = queryprofile( app_hini, TEX_APP, 'USER1__MSG')
  763.     TEX_USER2_MENU_TEXT = queryprofile( app_hini, TEX_APP, 'USER2_MENU_TEXT')
  764.     TEX_USER2__MSG = queryprofile( app_hini, TEX_APP, 'USER2__MSG')
  765.     TEX_USER3_MENU_TEXT = queryprofile( app_hini, TEX_APP, 'USER3_MENU_TEXT')
  766.     TEX_USER3__MSG = queryprofile( app_hini, TEX_APP, 'USER3__MSG')
  767.     TEX_USER4_MENU_TEXT = queryprofile( app_hini, TEX_APP, 'USER4_MENU_TEXT')
  768.     TEX_USER4__MSG = queryprofile( app_hini, TEX_APP, 'USER4__MSG')
  769.  
  770. --  Temporarily delete Help menu so we can put it back later on the end
  771. --  of the menu bar where it belongs!
  772.     deletemenu defaultmenu, HELP_MENU_ID, 0, 0  -- delete the existing Help menu
  773.                                                 -- (we want it to stay at the right)
  774.  
  775. -- OS/2 menu
  776. compile if TEXFEPRO
  777. compile if defined(STD_MENU_NAME)
  778. -- the menu is not the standard one; we build our own OS/2 submenu
  779.    buildsubmenu  defaultmenu, 90, 'OS/~2', \1TEX_OS2__MSG, 0, 0
  780.      buildmenuitem defaultmenu,    90, 910, TEX_OSSHELL_MENU_TEXT, 'tex_osshell'\1TEX_OSSHELL__MSG, 0, 0
  781.      buildmenuitem defaultmenu,    90, 912, TEX_FOLDER_MENU_TEXT,  'tex_fm'\1TEX_FM__MSG,     0, 0
  782. compile else
  783. -- we add the OS/2 items to the "Command" and " File" submenus
  784.      buildmenuitem defaultmenu, 1, 105, \0,                      '',            4, 0
  785.      buildmenuitem defaultmenu, 1, 106, TEX_OSSHELL1_MENU_TEXT, 'tex_osshell'\1TEX_OSSHELL__MSG, 0, 0
  786.      buildmenuitem defaultmenu, 2, 212, \0,                      '',            4, 0
  787.      buildmenuitem defaultmenu, 2, 213, TEX_FOLDER1_MENU_TEXT,  'tex_fm'\1TEX_FM__MSG,     0, 0
  788. compile endif -- STD_MENU_NAME
  789. compile endif -- TEXFEPRO
  790.  
  791. -- TeX menu
  792. compile if defined (vtex)
  793.     buildsubmenu defaultmenu, 9, 'V~TeX', \1TEX_BAR__MSG, 0,0
  794. compile else
  795.     buildsubmenu defaultmenu, 9, '~TeX', \1TEX_BAR__MSG, 0,0
  796. compile endif
  797.       buildmenuitem defaultmenu, 9, 901, TEX_TEX_MENU_TEXT\9'Ctrl+F9',      'tex'\1TEX_TEX__MSG, 0,0
  798.       buildmenuitem defaultmenu, 9, 908, TEX_TEXPS_MENU_TEXT\9'Ctrl+F10',   'texps'\1TEX_TEXPS__MSG, 0,0
  799. compile if defined (vtex)
  800.       buildmenuitem defaultmenu, 9, 925, TEX_Q_MENU_TEXT, \1TEX_Q__MSG, 17, 0
  801.       buildmenuitem defaultmenu, 9, 926, TEX_TEXQ_MENU_TEXT,                'texq', 0,0
  802.       buildmenuitem defaultmenu, 9, 928, TEX_TEXQPS_MENU_TEXT,              'texqps', 32769,0
  803. compile endif      
  804.       buildmenuitem defaultmenu, 9, 924, TEX_LOCERR_MENU_TEXT\9'Ctrl+F11',  'tex_locate_error'\1TEX_LOCATE_ERROR__MSG, 0,0
  805.       buildmenuitem defaultmenu, 9, 905, TEX_VIEWLOG_MENU_TEXT\9'Ctrl+F12', 'tex_view_log'\1TEX_VIEWLOG__MSG,  0,0
  806.  
  807.       buildmenuitem defaultmenu, 9, 902, \0, '', 4, 0
  808. compile if defined (vtex)
  809.       buildmenuitem defaultmenu, 9, 923, TEX_VIEWPDF_MENU_TEXT, 'tex_view_pdf'\1TEX_VIEWPDF__MSG, 0,0
  810.       buildmenuitem defaultmenu, 9, 943, TEX_VIEWPS_MENU_TEXT, 'tex_view_ps'\1TEX_VIEWPS__MSG, 0,0
  811. compile else
  812.       buildmenuitem defaultmenu, 9, 903, TEX_VIEW_MENU_TEXT,   'tex_view_dvi'\1TEX_VIEWDVI__MSG,  0,0
  813.       buildmenuitem defaultmenu, 9, 943, TEX_VIEWPS_MENU_TEXT, 'tex_view_ps'\1TEX_VIEWPS__MSG, 0,0
  814.       buildmenuitem defaultmenu, 9, 923, TEX_VIEWPDF_MENU_TEXT, 'tex_view_pdf'\1TEX_VIEWPDF__MSG, 0,0
  815. compile endif
  816.       buildmenuitem defaultmenu, 9, 941, \0, '', 4, 0
  817. compile if not defined (vtex)      
  818.       if tex_check_print_exec() then      
  819.         buildmenuitem defaultmenu, 9, 904, TEX_PRINT_MENU_TEXT,  'tex_print'\1TEX_PRINT__MSG,  0,0
  820.       endif
  821.       buildmenuitem defaultmenu, 9, 944, TEX_DVIPS_MENU_TEXT\9'Ctrl+V',  'tex_dvips'\1TEX_DVIPS__MSG, 0,0
  822. compile endif      
  823.       if TEX_USER1_MENU_TEXT <> '' then
  824.         buildmenuitem defaultmenu, 9, 911, TEX_USER1_MENU_TEXT,'texuser1exec' \1TEX_USER1__MSG, 0,0
  825.       endif
  826.       if TEX_USER2_MENU_TEXT <> '' then
  827.         buildmenuitem defaultmenu, 9, 921, TEX_USER2_MENU_TEXT,'texuser2exec' \1TEX_USER2__MSG, 0,0
  828.       endif
  829.       if TEX_USER3_MENU_TEXT <> '' then
  830.         buildmenuitem defaultmenu, 9, 930, TEX_USER3_MENU_TEXT,'texuser3exec' \1TEX_USER3__MSG, 0,0
  831.       endif
  832.       if TEX_USER4_MENU_TEXT <> '' then
  833.         buildmenuitem defaultmenu, 9, 933, TEX_USER4_MENU_TEXT,'texuser4exec' \1TEX_USER4__MSG, 0,0
  834.       endif
  835.  
  836.       buildmenuitem defaultmenu, 9, 927, \0, '', 4, 0
  837.       buildmenuitem defaultmenu, 9, 931, TEX_CONF_MENU_TEXT,'texfe_settings_window' \1TEX_CONF__MSG,0,0
  838. compile if TEXFEPRO
  839.       buildmenuitem defaultmenu, 9, 940, TEX_MFS_MENU_TEXT, 'tex_master_file_support' \1TEX_MASTER__MSG,0,0
  840. compile endif
  841.  
  842. compile if not TEXFEPRO
  843.       buildmenuitem defaultmenu, 9, 917, \0, '',4, 0
  844.       buildmenuitem defaultmenu, 9, 910, TEX_OSSHELL2_MENU_TEXT, 'tex_osshell'\1TEX_OSSHELL__MSG, 0, 0
  845.       buildmenuitem defaultmenu, 9, 912, TEX_FOLDER2_MENU_TEXT,  'tex_fm'\1TEX_FM__MSG,     0, 0
  846. compile endif
  847.  
  848.       buildmenuitem defaultmenu, 9, 922, \0, '', 4, 0
  849.       buildmenuitem defaultmenu, 9, 929, TEX_ABOUT_MENU_TEXT, 'tex_ver' HELP_PROD_MENUP__MSG,0,0
  850.  
  851. /* unused 916 */
  852.  
  853.       call readd_help_menu();   -- Put Help menu back in
  854.       showmenu defaultmenu
  855. compile endif -- WANT_TEX_MENU
  856.  
  857.  
  858. /*****************************/
  859. /*                           */
  860. /*  Set margins to infinity  */
  861. /*                           */
  862. /*****************************/
  863.  
  864. compile if EXTENDED_LATEX_ASSIST
  865. defproc setTexMargins
  866.    universal expand_on
  867.    if (tex_is_doc() or tex_is_style()) and expand_on then  
  868.      -- if TeX doc/style loaded and syntax expansion is on
  869.      .margins = '1 1599 1'
  870.    endif
  871. compile endif /* EXTENDED_LATEX_ASSIST */
  872.  
  873.  
  874. /**************************/
  875. /*                        */
  876. /*  Enable highlighting   */
  877. /*                        */
  878. /**************************/
  879.  
  880. defproc setTexHilite
  881.     universal  app_hini
  882.  
  883. if .visible and
  884.    tex_is_file() and not ( (filetype()='DTX' or filetype()='FDD') ) and
  885.    queryprofile(app_hini, TEX_APP, 'TEX_SYNTAXHILITE') then
  886.       'toggle_parse 1 EPMKWDS.TEX'
  887. endif
  888.  
  889.  
  890. /********************/
  891. /*                  */
  892. /*  Execute TeX     */
  893. /*                  */
  894. /********************/
  895.  
  896. defc tex
  897.    call tex_run_tex(0, 0)  -- run TeX
  898.  
  899. defc texps
  900.    call tex_run_tex(1, 0)  -- run TeX and dvips
  901.  
  902. compile if defined (vtex)
  903.  
  904. defc texq
  905.    call tex_run_tex(0, 1)
  906.  
  907. defc texqps
  908.    call tex_run_tex(1, 1)
  909.  
  910. compile endif   
  911.    
  912. defproc tex_run_tex(ps, quick) -- here we do the real work
  913.  
  914.    universal  tex_log_file_line,
  915.               tex_log_file_curr,
  916.               tex_log_file_name,
  917.               app_hini,
  918.               tex_debug
  919.  
  920. -- bail out, if not a TeX document
  921.    if not tex_is_doc() then
  922.        sayerror TEX_NODOC_STRING
  923.        RETURN
  924.    endif
  925.    
  926. compile if WANT_INCLUDEONLY_SUPPORT
  927. -- clear name of included file   
  928.    istem = ''
  929. compile endif  
  930.  
  931. -- memorize id of file being edited
  932.    getfileid working_fid
  933.  
  934. -- If a line or character mark exists, then ask whether only the 
  935. -- marked region is to be processed;  indicate this by process_mark = 1.
  936.    process_mark = 0
  937.    if ((marktype() = 'LINE') or (marktype() = 'CHAR')) then
  938.       getmark a,b,c,d,marked_fid
  939.       process_mark = (marked_fid = working_fid) -- mark is in the current file
  940.    endif
  941.    if process_mark then
  942.       rc = WinMessageBox(TEX_MARK1_STRING,
  943.                       TEX_MARK2_STRING,
  944.                       MB_YESNOCANCEL+MB_NOICON+MB_DEFBUTTON1+MB_MOVEABLE)
  945.       if rc = MBID_NO then 
  946.          process_mark = 0 -- proceed as usual
  947.       elseif rc = MBID_CANCEL then
  948.          RETURN  -- cancel
  949.       endif
  950.    endif
  951.  
  952. -- If master file system is enabled, then check for master file
  953.  
  954.     tex_master= queryprofile( app_hini, TEX_APP, 'TEX_MASTERFILE')
  955.     if tex_master then  /* master file system enabled */
  956.         master = tex_master_name(TEX_TEX_TITLE)
  957.  
  958. -- Need to change to master file to get Format from first line
  959. -- And TeX in that directory
  960.  
  961.         if master = '-1' then   -- master file specified but not found on disk
  962.            RETURN
  963.         endif
  964.  
  965.         if master = '' then  -- no master file specified
  966.             sayerror .filename||TEX_M_ASSUME_STRING
  967.             call tex_parse_filename(.filename,dr,dir,stem,ext)
  968.             call tex_check_for_save()
  969.         else   -- a master file is being used
  970.             sayerror TEX_M_NAME_STRING||master
  971. compile if WANT_INCLUDEONLY_SUPPORT
  972.             -- memorize name of included file (lowercase)
  973.             call tex_parse_filename(lowcase(.filename),idr,idir,istem,iext)
  974. compile endif
  975.             call tex_parse_filename(master,dr,dir,stem,ext)
  976.             if tex_file_in_ring(master) then
  977.                 getfileid master_fid,master
  978.                 activatefile master_fid
  979.                 call tex_check_for_save()
  980.             else
  981.                 'edit /d' master
  982.                 getfileid master_fid
  983.             endif
  984.         endif
  985.  
  986. -- Here we look for file dependencies in the file to be formatted
  987. -- and if dependent files are loaded in the editor
  988. -- they are checked for modification as well.
  989. -- Notes:
  990. --    * we search each line of the file so this can be a real
  991. --      performance bottleneck with large files
  992. --    * nested dependencies more than one level deep are ignored
  993. --
  994. --  We recognize 3 methods to specify an included file:
  995. --  LaTeX: \include{file} or \input{file}
  996. --  TeX:   \input file
  997.  
  998.         getfileid source_fid
  999.         for counter = 1 to .last
  1000.             getline line, counter
  1001.             if pos('%', strip(line)) <> 1 then  -- line doesn't start with %
  1002.                 parse value line with '\include{' dep_fname '}' .
  1003.                 if dep_fname = '' then
  1004.                    parse value line with '\input{' dep_fname '}' .
  1005.                    if dep_fname = '' then
  1006.                       parse value line with '\input ' dep_fname .
  1007.                    endif
  1008.                 endif
  1009.             else
  1010.                dep_fname = ''
  1011.             endif
  1012.  
  1013.             if dep_fname <> '' then
  1014. -- Translate from unix-style to OS/2-style and add '.tex' extension if missing
  1015.                dep_fname = translate(strip(dep_fname),'\','/')
  1016.                n = lastpos('\',dep_fname)
  1017.                tmp = substr(dep_fname,n+1)
  1018.                if lastpos('.', tmp) <> length(tmp) then
  1019.                   parse value tmp with  tmpStem '.' tmpExt
  1020.                   if tmpExt = ''  then
  1021.                       dep_fname = dep_fname||'.tex'
  1022.                   endif
  1023.                else
  1024.                   -- the given filename ends with '.', so
  1025.                   -- we remove the '.' to get the real name
  1026.                   dep_fname = substr(dep_fname, 1, length(dep_fname)-1)
  1027.                endif
  1028.                sayerror TEX_CHKDEP_STRING||dep_fname
  1029.                if tex_file_in_ring(dep_fname) = 1 then
  1030.                    getfileid dep_fid,dep_fname
  1031.                    activatefile dep_fid
  1032.                    call tex_check_for_save()
  1033.                    activatefile source_fid   /* restore source file */
  1034.                endif
  1035.             endif
  1036.         endfor
  1037.     else /* master file system disabled */
  1038.         call tex_parse_filename(.filename,dr,dir,stem,ext)
  1039.         call tex_check_for_save()
  1040.         master = ''
  1041.     endif /* tex_master */
  1042.  
  1043. -- determine format to use
  1044.         format = tex_auto_format()
  1045.  
  1046. compile if not defined (vtex)
  1047. -- get name of TeX program for the requested format
  1048.    texprog = queryprofile(app_hini, TEX_APP, translate(format))
  1049.    if texprog = '' then
  1050.       texprog = format||'.CMD'
  1051.    endif
  1052. compile else
  1053.    texprog = 'vtex'
  1054. compile endif   
  1055.  
  1056. -- Change working directory to directory of current file since that is
  1057. -- where the .DVI and .LOG files (and any others) should go.
  1058.    call tex_cd()
  1059.  
  1060. -- TeX marked region only?
  1061.    if process_mark then
  1062.       getfileid current_fid  -- memorize current file
  1063.       'edit /n 'stem'.___'   -- create temporary file
  1064.       -- first we locate the end of the preamble;
  1065.       bye = ''
  1066.       do counter = 1 to current_fid.last
  1067.          getline line, counter, current_fid
  1068.          insertline line
  1069.          if pos('\begin{document}', line) then
  1070.             bye = '\end{document}'
  1071.             leave
  1072.          endif
  1073.          if pos('%**end of header', line) then
  1074.             bye = '\bye'
  1075.             leave
  1076.          endif
  1077.       enddo
  1078.       if bye = '' then
  1079.          .modify = 0; 
  1080.          'quit'
  1081.          activatefile current_fid
  1082.          call WinMessageBox('TeX', TEX_MARK3_STRING,
  1083.                             MB_OK+MB_WARNING+MB_MOVEABLE)
  1084.          RETURN
  1085.          -- we stay in the file the above warning refers to !
  1086.       endif
  1087.       -- now copy the marked lines from marked_fid to temporary file
  1088.       do counter = a to b
  1089.          getline line, counter, marked_fid
  1090.          if ((marktype() = 'CHAR') and (a=b)) then
  1091.             line = substr(line,c,(d-c+1))
  1092.          elseif ((marktype() = 'CHAR') and (counter=a)) then
  1093.             line = substr(line,c)
  1094.          elseif ((marktype() = 'CHAR') and (counter=b)) then
  1095.             line = substr(line,1,d)
  1096.          endif
  1097.          insertline line
  1098.       enddo
  1099.       insertline bye
  1100.       'file' -- save and quit temporary file
  1101.       activatefile current_fid  -- return to main document
  1102.       ext = '___'
  1103. compile if WANT_INCLUDEONLY_SUPPORT
  1104. --    clear name of included file, if TeXing a marked region only
  1105.       istem = ''
  1106. compile endif      
  1107.    endif /* process_mark */
  1108.  
  1109. compile if WANT_INCLUDEONLY_SUPPORT
  1110. -- include working file only
  1111.    if istem <> ''  then 
  1112.       -- TeXing was requested while an included file was being edited
  1113.       do counter = 1 to .last -- we are in the master file now!
  1114.          getline line, counter
  1115.          if pos('\begin{document}', line) then
  1116.             leave
  1117.          endif
  1118.          parse value line with code '%'
  1119.          parse value code with '\includeonly{' junk
  1120.          if junk <> '' then
  1121.             newline = '\includeonly{' || istem || '}'
  1122.             replaceline newline, counter
  1123.             'Save'
  1124.             sayerror newline
  1125.             leave
  1126.          endif
  1127.       enddo
  1128.    endif
  1129. compile endif
  1130.  
  1131. -- Put together the TeX command from the following parts:
  1132. --    texprog 
  1133. --    stem 
  1134. --    ext
  1135.  
  1136. compile if defined (vtex)
  1137.    if ps=1 then
  1138.       vtexoptions = queryprofile(app_hini, TEX_APP, 'PS_OPTIONS')
  1139.    else
  1140.       vtexoptions = queryprofile(app_hini, TEX_APP, 'PDF_OPTIONS')
  1141.    endif
  1142.    if quick=1 then
  1143.       vtexoptions = '-q ' || vtexoptions
  1144.    endif
  1145.    cmdline = texprog || ' '  || vtexoptions || ' @' || format || ' ' || stem
  1146.    if translate(ext) <> 'TEX' then -- add extension
  1147.       cmdline = cmdline||'.'||ext
  1148.    endif
  1149.    cmdline = '"' cmdline '& if errorlevel 3 pause "'
  1150.    -- start cmd.exe and pass it the above command line
  1151.    command = 'start "VTeX" /f /n cmd.exe /c' cmdline
  1152. compile else
  1153.    cmdline = texprog || ' ' || stem
  1154.    if translate(ext) <> 'TEX' then -- add extension
  1155.       cmdline = cmdline||'.'||ext
  1156.    endif
  1157.    if ps=1 then
  1158.       -- run TeX and dvips in sequence; 
  1159.       -- first we need the name of the dvips program
  1160.       dvips = queryprofile(app_hini, TEX_APP, 'DVIPS_EXEC')
  1161.       -- an example what to execute:
  1162.       -- "( latex myprog.dtx && dvips32 myprog ) || pause "
  1163.       cmdline = '"(' cmdline '&&' dvips stem ') || pause "'
  1164.       -- start cmd.exe and pass it the above command line
  1165.       command = 'start "TeX/PS" /f /n cmd.exe /c ' cmdline
  1166.    else
  1167.       -- run TeX only
  1168.       command = 'start /f /c "TeX"' cmdline
  1169.    endif
  1170. compile endif
  1171.  
  1172. -- launch the TeX command
  1173.     if tex_debug=1 then sayerror command; endif
  1174.     command
  1175.     if rc <> 0 then
  1176.       sayerror command || TEX_CMDFAIL_STRING || rc
  1177.       call tex_cmderror('TeX')
  1178.     else
  1179.       -- Memorize fully qualified name of current log file
  1180.       tex_log_file_name = dr||dir||stem||'.log'
  1181.       call setprofile(app_hini, TEX_APP, 'LOGFILE', tex_log_file_name)
  1182.       -- Remove old LOG file from the ring after successful TeX compilation
  1183.       if tex_file_in_ring(tex_log_file_name) = 1 then
  1184.         getfileid log_fid,tex_log_file_name
  1185.         activatefile log_fid
  1186.         .modify = 0             -- set this in case user modified file
  1187.         'quit'                  -- close the file
  1188.       endif
  1189.       -- Can't load new log file here unless we wait for TeX to finish
  1190.       tex_log_file_line = 1
  1191.       tex_log_file_curr = 1
  1192.       -- need this in case the log file will be loaded manually
  1193.     endif /* rc <> 0 */
  1194.  
  1195. -- Change back to file from which we called TeX if we changed it
  1196.     getfileid current_fid
  1197.     if current_fid <> working_fid then
  1198.         activatefile working_fid
  1199.     endif
  1200. RETURN
  1201.  
  1202.  
  1203. compile if not defined (vtex)
  1204. /********************/
  1205. /*                  */
  1206. /*   DVI preview    */
  1207. /*                  */
  1208. /********************/
  1209.  
  1210. defc tex_view_dvi
  1211.     universal  app_hini
  1212.  
  1213.     command = queryprofile( app_hini, TEX_APP, 'VIEW_CMD')
  1214.     call tex_run_cmd('.dvi', command, TEX_VIEW_TITLE, 'TEX_VIEW_DVI_OPT')
  1215. compile endif
  1216.  
  1217.  
  1218. compile if not defined (vtex)
  1219. /***************/
  1220. /*             */
  1221. /*   Print     */
  1222. /*             */
  1223. /***************/
  1224.  
  1225. defc tex_print
  1226.     universal  app_hini
  1227.     
  1228.     command = queryprofile( app_hini, TEX_APP, 'PRINT_CMD')
  1229.     call tex_run_cmd('.dvi', command, TEX_PRINT_TITLE, 'TEX_PRINT_OPT')
  1230. compile endif
  1231.  
  1232.  
  1233. /********************/
  1234. /*                  */
  1235. /*   PS preview     */
  1236. /*                  */
  1237. /********************/
  1238.  
  1239. defc tex_view_ps
  1240.     universal  app_hini
  1241.  
  1242.     command = queryprofile( app_hini, TEX_APP, 'VIEWPS_CMD')
  1243.     call tex_run_cmd('.ps', command, TEX_VIEWPS_TITLE, 'TEX_VIEWPS_OPT')
  1244.  
  1245.  
  1246. /********************/
  1247. /*                  */
  1248. /*  PDF preview     */
  1249. /*                  */
  1250. /********************/
  1251.  
  1252. defc tex_view_pdf
  1253.     universal  app_hini
  1254.  
  1255.     command = queryprofile( app_hini, TEX_APP, 'VIEWPDF_CMD')
  1256.     call tex_run_cmd('.pdf', command, TEX_VIEWPDF_TITLE, 'TEX_VIEWPDF_OPT')
  1257.  
  1258.  
  1259. compile if not defined (vtex)
  1260. /**************/
  1261. /*            */
  1262. /*   dvips    */
  1263. /*            */
  1264. /**************/
  1265.  
  1266. defc tex_dvips
  1267.     universal  app_hini
  1268.  
  1269.     dvips = queryprofile( app_hini, TEX_APP, 'DVIPS_EXEC')
  1270.     if dvips = '' then
  1271.        sayerror TEX_NODVIPS_STRING
  1272.        RETURN
  1273.     else
  1274.     endif
  1275.     cmdline = '"' dvips '[' dvips '] %**N || pause"'
  1276.     -- pass the above command line to cmd.exe
  1277.     command  = 'start /f /n cmd.exe /C' cmdline
  1278.     call tex_run_cmd('.dvi', command, TEX_DVIPS_TITLE, 'TEX_DVIPS_OPT')
  1279. compile endif
  1280.  
  1281.  
  1282. /**********************/
  1283. /*                    */
  1284. /*   View log file    */
  1285. /*                    */
  1286. /**********************/
  1287.  
  1288. defc tex_view_log
  1289.     universal  tex_log_file_curr,
  1290.                tex_log_file_name,
  1291.                tex_error_fname,
  1292.                app_hini,
  1293.                tex_debug
  1294.  
  1295. -- lockout if there is no "current" log file yet
  1296. if not tex_current_log() then
  1297.    sayerror TEX_NOCURRLOG_STRING
  1298.    RETURN
  1299. endif
  1300.  
  1301. call tex_parse_filename(tex_log_file_name,dr,dir,stem,ext)
  1302.  
  1303. -- if there are still errors to be processed, 
  1304. -- AND the log file is still in the ring:
  1305. if tex_more_errors() and tex_file_in_ring(tex_log_file_name) then
  1306.     getfileid log_fid,tex_log_file_name
  1307.     getfileid current_fid
  1308.     activatefile log_fid
  1309.     -- if we are alreay in the log file, then start again at 1st error
  1310.     if current_fid = log_fid then
  1311.        call tex_parse_init()
  1312.     endif
  1313.     -- go to current error, if possible
  1314.     if tex_log_file_curr <= .last then
  1315.        .line = tex_log_file_curr
  1316.     endif
  1317. -- No (more) errors or log file not in the ring?
  1318. -- Then get rid of old copy in ring if it exists; edit new one.
  1319. -- (Is this really necessary?)
  1320. else
  1321.    if tex_file_in_ring(tex_log_file_name) then
  1322.        getfileid log_fid,tex_log_file_name
  1323.        activatefile log_fid
  1324.        .modify = 0             -- set this in case user modified file
  1325.        'quit'                  -- close the file
  1326.    else
  1327.        tex_log_file_curr = 3 -- forget location of last error
  1328.    endif
  1329.    if not exist(tex_log_file_name) then
  1330.      call WinMessageBox(TEX_VIEWLOG_TITLE, TEX_L_LOG_STRING||
  1331.                         tex_log_file_name||TEX_NOTFOUND_STRING,
  1332.                         MB_OK+MB_WARNING+MB_MOVEABLE)
  1333.      -- clear the current log file name
  1334.      tex_log_file_name = ''
  1335.      call setprofile(app_hini, TEX_APP, 'LOGFILE', '')
  1336.      RETURN
  1337.    endif
  1338.    'edit /d /r' tex_log_file_name
  1339.     -- show location of last error
  1340.     if tex_log_file_curr <= .last then
  1341.        .line = tex_log_file_curr
  1342.     endif
  1343. -- initialize the parsing routines
  1344.    tex_error_fname = dr||dir||stem||'.tex' -- ?
  1345.    call tex_parse_init()
  1346. endif
  1347.  
  1348.  
  1349. /*************************/
  1350. /*                       */
  1351. /*   The user commands   */
  1352. /*                       */
  1353. /*************************/
  1354.  
  1355. defc texuser1exec
  1356.    universal app_hini
  1357.  
  1358.    UserMenuText = queryprofile( app_hini, TEX_APP, 'USER1_MENU_TEXT')
  1359.    UserMenuTexT = translate(UserMenuText, '', '~')
  1360.    UserExt = queryprofile( app_hini, TEX_APP, 'USER1_EXT')
  1361.    command = queryprofile( app_hini, TEX_APP, 'USER1_CMD')
  1362.    key = 'USER1_OPT'
  1363.    call tex_run_cmd(UserExt, command, UserMenuText, key)
  1364.  
  1365. defc texuser2exec
  1366.    universal app_hini
  1367.  
  1368.    UserMenuText = queryprofile( app_hini, TEX_APP, 'USER2_MENU_TEXT')
  1369.    UserMenuTexT = translate(UserMenuText, '', '~')
  1370.    UserExt = queryprofile( app_hini, TEX_APP, 'USER2_EXT')
  1371.    command = queryprofile( app_hini, TEX_APP, 'USER2_CMD')
  1372.    key = 'USER2_OPT'
  1373.    call tex_run_cmd(UserExt, command, UserMenuText, key)
  1374.  
  1375. defc texuser3exec
  1376.    universal app_hini
  1377.  
  1378.    UserMenuText = queryprofile( app_hini, TEX_APP, 'USER3_MENU_TEXT')
  1379.    UserMenuTexT = translate(UserMenuText, '', '~')
  1380.    UserExt = queryprofile( app_hini, TEX_APP, 'USER3_EXT')
  1381.    command = queryprofile( app_hini, TEX_APP, 'USER3_CMD')
  1382.    key = 'USER3_OPT'
  1383.    call tex_run_cmd(UserExt, command, UserMenuText, key)
  1384.  
  1385. defc texuser4exec
  1386.    universal app_hini
  1387.  
  1388.    UserMenuText = queryprofile( app_hini, TEX_APP, 'USER4_MENU_TEXT')
  1389.    UserMenuTexT = translate(UserMenuText, '', '~')
  1390.    UserExt = queryprofile( app_hini, TEX_APP, 'USER4_EXT')
  1391.    command = queryprofile( app_hini, TEX_APP, 'USER4_CMD')
  1392.    key = 'USER4_OPT'
  1393.    call tex_run_cmd(UserExt, command, UserMenuText, key)
  1394.  
  1395.  
  1396. /***************************************/
  1397. /*                                     */
  1398. /*   Execute an external command       */
  1399. /*                                     */
  1400. /***************************************/
  1401.  
  1402. defproc tex_run_cmd(FileExt, cmd, title, optname) =
  1403.  
  1404. -- Arguments:
  1405. -- FileExt      check for the existence of this file type first
  1406. -- cmd          the command to be executed 
  1407. -- title        use this as the title for error messages
  1408. -- optname      save extra options under this key in the INI file
  1409.  
  1410. universal app_hini,
  1411.           tex_debug
  1412.  
  1413. if cmd = '' then
  1414.    beep(440,125)
  1415.    sayerror TEX_NOCONFIG_STRING
  1416.    RETURN
  1417. endif
  1418.  
  1419. -- If master file system is enabled, then check for master file
  1420. tex_master= queryprofile( app_hini, TEX_APP, 'TEX_MASTERFILE')
  1421. if tex_master  then
  1422.     master = tex_master_name(title)
  1423.     if master = '-1' then
  1424.        RETURN
  1425.     endif
  1426.     if master = '' then
  1427.         sayerror .filename||TEX_M_ASSUME_STRING
  1428.         call tex_parse_filename(.filename,dr,dir,stem,ext)
  1429.     else
  1430.         sayerror TEX_M_NAME_STRING||master
  1431.         call tex_parse_filename(master,dr,dir,stem,ext)
  1432.     endif
  1433. else
  1434.    call tex_parse_filename(.filename,dr,dir,stem,ext)
  1435. endif /* masterfile support */
  1436.  
  1437. -- lockout if file does not exist
  1438. if FileExt <> '' then
  1439.    if not exist(dr||dir||stem||FileExt) then
  1440.       sayerror FileExt||TEX_NOEX2_STRING
  1441.       RETURN
  1442.    endif
  1443. endif
  1444.  
  1445. -- Substitute the filename in the command string
  1446. command = tex_makecmd(cmd, stem, ext)
  1447.  
  1448. -- Evaluate options to be entered interactively
  1449. if pos('[',command) and optname <> '' then
  1450.     parse value command with lcommand '[' prompttext ']' rcommand
  1451.     curopts = queryprofile( app_hini, TEX_APP, optname)
  1452.     sbuf = entrybox(title, 
  1453.                     TEX_XOPT_BUTTONS,
  1454.                     curopts,60,62,
  1455.                     atoi(1) ||            -- default button # 
  1456.                     atoi(0) ||            -- help panel ID (0 for no help)
  1457.                     gethwnd(APP_HANDLE) ||
  1458.                     TEX_ADDOPT_STRING||prompttext||\0) 
  1459.                                           -- prompt
  1460.     button = asc(leftstr(sbuf,1))
  1461.     if button=3 or button=0 then RETURN; endif -- Cancel or closed otherwise
  1462.     if button=2 then                           -- Use std. options
  1463.        options = ''
  1464.     else                                       -- Use extra options
  1465.        EOS = pos(\0,sbuf,2)    -- CHR(0) signifies End Of String
  1466.        options = substr(sbuf,2,EOS-2)
  1467.        call setprofile( app_hini, TEX_APP, optname, options)
  1468.     endif
  1469.     command = lcommand||options||rcommand
  1470. endif
  1471.  
  1472. -- tell the user that the command is going to be launched:
  1473. sayerror title
  1474.  
  1475. --  Change working directory to directory of current/master file since that is
  1476. --  where the .DVI and .LOG files (and any others) should go.
  1477.  
  1478. savedir = directory()    -- save directory **
  1479. tstr = dr || leftstr(dir,length(dir)-1)
  1480. if not (savedir = tstr) then
  1481.     if tex_debug then sayerror 'Changing to directory 'tstr; endif
  1482.     call directory(tstr)     -- change directory **
  1483. endif
  1484.  
  1485. -- launch the command
  1486. if tex_debug=1 then sayerror command; endif
  1487. command
  1488. if rc <> 0 then
  1489.   sayerror command || TEX_CMDFAIL_STRING || rc
  1490.   call tex_cmderror(title)
  1491. endif
  1492.  
  1493. -- change back to directory from where we called the command
  1494. ;if not (savedir = tstr) then
  1495. ;   if tex_debug then sayerror 'Back to directory 'savedir; endif
  1496. ;   call directory(savedir)  -- restore directory **
  1497. ;endif
  1498.  
  1499.  
  1500. /******************************************************/
  1501. /*                                                    */
  1502. /*   Read LOG file and find errors in source code     */
  1503. /*                                                    */
  1504. /******************************************************/
  1505.  
  1506. defc tex_locate_error
  1507.    universal tex_log_file_name
  1508.  
  1509. -- lockout if there is no "current" log file yet
  1510. if not tex_current_log() then
  1511.    sayerror TEX_NOCURRLOG_STRING
  1512.    RETURN
  1513. endif
  1514.  
  1515. if tex_more_errors() then  -- more errors to be shown?
  1516.     call tex_find_errors()
  1517. else
  1518.     sayerror TEX_NOERRORS_STRING
  1519. endif
  1520.  
  1521.  
  1522. /***************************/
  1523. /*                         */
  1524. /*   Product information   */
  1525. /*                         */
  1526. /***************************/
  1527. defc tex_ver
  1528.    call WinMessageBox(TEX_ABOUT_TITLE,
  1529.                       'TeX Front End'||TEXFE_VERSION_STRING||TEXFE_VERSION\13||
  1530.                       TEXFE_COPYRIGHT\13\13||
  1531.                       TEXFE_THANKS_STRING,
  1532.                       MB_OK+MB_INFORMATION+MB_DEFBUTTON1+MB_MOVEABLE)
  1533.  
  1534.  
  1535. /*
  1536. ┌────────────────────────────────────────────────────────────────────────────┐
  1537. │  Procedure definitions                                                     │
  1538. └────────────────────────────────────────────────────────────────────────────┘
  1539. */
  1540.  
  1541. -----------------------------------------------------------------------------
  1542. -- Determine format to use with this file from first line of the file.
  1543. -- Same specification as Eberhard Mattes' TEXIT.CMD distributed with emTeX.
  1544. -- The default format is DEFAULT_FORMAT.
  1545.  
  1546. defproc tex_auto_format =
  1547.     universal app_hini
  1548.  
  1549.     format = ''
  1550.     getline line, 1
  1551.     line = translate(line)
  1552.     parse value line with '%'  'FORMAT' ':' format .
  1553.     if format = '' then
  1554.         parse value line with '%'  'FORMAT' format .
  1555.     endif
  1556.  
  1557.     if format = '' then
  1558.        format = queryprofile (app_hini, TEX_APP, 'DEFAULT_FORMAT')
  1559.        sayerror TEX_NO_FORMAT_STRING||format||TEX_USE_FORMAT_STRING
  1560.     else
  1561.        sayerror TEX_FORMAT_STRING||format||TEX_USE_FORMAT_STRING
  1562.     endif
  1563.     return format
  1564.  
  1565. -----------------------------------------------------------------------------
  1566. compile if TEXFEPRO 
  1567. -- Called from mymniuni.e to determine if file of given type exists for the 
  1568. -- associated master file, or for current file.
  1569. -- Returns:  1 if file does not exist or if the master file does not exist
  1570. --           0 if the file exists 
  1571.  
  1572. defproc tex_check_exist(FileExt) =
  1573.     universal  app_hini
  1574.  
  1575. -- If master file system is enabled, then check for master file
  1576.     if queryprofile( app_hini, TEX_APP, 'TEX_MASTERFILE') then 
  1577.         master = tex_master_name()
  1578.         if master = '' then
  1579.             fname = .filename
  1580.         else
  1581.             fname = master
  1582.         endif
  1583.     else
  1584.         fname = .filename
  1585.     endif -- master file support
  1586.     if fname = '-1' then
  1587.        ret = 1
  1588.     else
  1589.        if FileExt = '' then
  1590.           ret= 0
  1591.        else
  1592.           call tex_parse_filename(fname,dr,dir,stem,ext)
  1593.           ret = not exist(dr||dir||stem||FileExt)
  1594.        endif
  1595.     endif
  1596. return ret
  1597. compile endif /* TEXFEPRO */
  1598.  
  1599. -----------------------------------------------------------------------------
  1600. compile if TEXFEPRO
  1601. -- get the value of USER?_EXT
  1602.  
  1603. defproc get_tex_user_ext =
  1604.     universal  app_hini
  1605.  
  1606.     if arg(1) = 1 then
  1607.         return  queryprofile(app_hini, TEX_APP, 'USER1_EXT')
  1608.     elseif arg(1) = 2 then
  1609.         return  queryprofile(app_hini, TEX_APP, 'USER2_EXT')
  1610.     elseif arg(1) = 3 then
  1611.         return  queryprofile(app_hini, TEX_APP, 'USER3_EXT')
  1612.     elseif arg(1) = 4 then
  1613.         return  queryprofile(app_hini, TEX_APP, 'USER4_EXT')
  1614.     else
  1615.          return ''
  1616.     endif
  1617.     
  1618. compile endif /* TEXFEPRO */
  1619.  
  1620. -----------------------------------------------------------------------------
  1621. compile if not defined (vtex)
  1622. defproc tex_check_print_exec = 
  1623.    universal app_hini
  1624.    
  1625.    return queryprofile(app_hini, TEX_APP, 'PRINT_CMD') <> ''
  1626. compile endif   
  1627.    
  1628. -----------------------------------------------------------------------------
  1629. compile if TEXFEPRO
  1630. -- determine if TEX_USER?_MENU_TEXT is defined
  1631.  
  1632. defproc tex_check_user_exec =
  1633.     universal app_hini
  1634.  
  1635.     if arg(1) = 1 then
  1636.         return  queryprofile(app_hini, TEX_APP, 'USER1_MENU_TEXT') <> ''
  1637.     elseif arg(1) = 2 then
  1638.         return  queryprofile(app_hini, TEX_APP, 'USER2_MENU_TEXT') <> ''
  1639.     elseif arg(1) = 3 then
  1640.         return  queryprofile(app_hini, TEX_APP, 'USER3_MENU_TEXT') <> ''
  1641.     elseif arg(1) = 4 then
  1642.         return  queryprofile(app_hini, TEX_APP, 'USER4_MENU_TEXT') <> ''
  1643.     else
  1644.          return 0
  1645.     endif
  1646. compile endif /* TEXFEPRO */
  1647.  
  1648. -----------------------------------------------------------------------------
  1649. --  Check to see if current file has been modified.  If it has, save it.
  1650.  
  1651. defproc tex_check_for_save =
  1652.  
  1653.     if .modify then
  1654.        'Save'
  1655.     endif
  1656.  
  1657. -----------------------------------------------------------------------------
  1658. /*
  1659. Extract master file name from first line of file
  1660.  
  1661. Returns: a) '' if master file is not specified;
  1662.          b) master file name with path added on if file exists;
  1663.          c) '-1', if master file is specified but doesn't exist.
  1664.  
  1665. If arg(1) <> '' AND the master file is specified, but doesn't
  1666. exist, a warning message is displayed, using arg(1) as the title.
  1667. */
  1668.  
  1669. defproc tex_master_name
  1670.     universal  app_hini
  1671.  
  1672.     master = ''
  1673.     getline line, 1
  1674.     parse value line with '%' . 'master' ':' master .
  1675.     if master = '' then
  1676.         parse value line with '%' . 'master' master .
  1677.         if master = '' then
  1678.             parse value line with '%' . 'Master'  ':' master .
  1679.             if master = '' then
  1680.                 parse value line with '%' . 'Master'  master .
  1681.             endif
  1682.         endif
  1683.     endif
  1684.  
  1685.     if master <> '' then
  1686.         master = translate(master,'\','/') -- convert to DOS format
  1687.         if lastpos('\', master) >= lastpos('.',master) then
  1688.            -- there is no '.' in the name
  1689.            master = master||'.tex'
  1690.         endif
  1691. --  *** bug: filename. -> filename..tex
  1692.  
  1693. --  Now, make the master filename fully qualified. 
  1694. --      First we determine current drive and dir;
  1695.         tex_parse_filename(.filename,dr,dir,stem,ext)
  1696. --      If there is a colon in the filename, then we're finished:
  1697.         if not pos(':',master) then
  1698. --         does the name start with '..' ?
  1699.            if pos('..', master) = 1 then
  1700.               call tex_cd() -- switch to dir. of current file
  1701.               currdir = directory() -- save current directory
  1702.               call directory('..')
  1703.               master = substr(master,3) -- must include backslash!
  1704.               mdir = directory()  -- does not include backslash!
  1705.               master = mdir||master
  1706.               call directory(currdir) -- restore directory
  1707. --         does the name start with '.\' ?              
  1708.            elseif pos('.\', master) = 1 then
  1709.               master = substr(master,3)
  1710.               master = dr||dir||master
  1711. --         absolute path, without drive letter?              
  1712.            elseif pos('\',master) = 1 then
  1713.               master = dr||master
  1714.            else
  1715. --         it must be a relative path then:
  1716. --         add drive letter and current dir
  1717.               master = dr||dir||master
  1718.            endif
  1719.         endif
  1720. -- Does the master file exist?
  1721.         if not exist(master) then
  1722.            if arg(1) <> '' then
  1723.               call WinMessageBox(arg(1), TEX_M_MASTER_STRING||master||
  1724.                                          TEX_NOTFOUND_STRING,
  1725.                                  MB_OK+MB_WARNING+MB_MOVEABLE)
  1726.            endif
  1727.            master = '-1'
  1728.         endif
  1729.     endif
  1730.     
  1731.     return master
  1732.  
  1733. -----------------------------------------------------------------------------
  1734. -- Parse a file name:  d:\dir1\dir2\file.ext
  1735. --                     \dir1\dir2\file.ext
  1736. --                     file.ext
  1737. --                     .ext
  1738. --                     \dir1\.ext
  1739. --                     ...etc,  but NOT d:test2.ext
  1740. -- returns  dr      d:
  1741. --          dir     \dir1\dir2\    if any of these does not exist,
  1742. --          stem    file           a null is returned.
  1743. --          ext     ext
  1744.  
  1745. defproc tex_parse_filename(fname, var dr, var dir, var stem, var ext)
  1746.  
  1747. -- Translate from Unix-style to OS/2-style names
  1748.     fname = translate(fname,'\','/')
  1749.     n = lastpos('\',fname)
  1750.     tmp = substr(fname,n+1)
  1751.     parse value tmp with  stem '.' ext
  1752.     tmp = substr(fname,1,n)
  1753.     n = pos(':',tmp)
  1754.     dr = substr(tmp,1,n)
  1755.     dir = substr(tmp,n+1)
  1756.  
  1757. -----------------------------------------------------------------------------
  1758. -- Determine if a file already is in ring.
  1759.  
  1760. defproc tex_file_in_ring(fname)
  1761.    universal tex_debug
  1762.    
  1763.    getfileid id, fname
  1764.    return (id <> '')
  1765. /*
  1766.     tex_parse_filename(fname,dr,dir,stem,ext)
  1767.     if ext = '' then
  1768.        return pfile_exists(stem)
  1769.     else
  1770.        return pfile_exists(stem||'.'||ext)
  1771.     endif
  1772. */
  1773.  
  1774. -----------------------------------------------------------------------------
  1775. -- Called to determine whether or not to disable
  1776. -- the error browsing facility.
  1777. -- Returns 1 if there can be more errors, 
  1778. --         0 if not or no "current" log file exists
  1779.  
  1780. defproc tex_more_errors
  1781.    universal  tex_log_file_line,
  1782.               tex_log_file_last,
  1783.               tex_log_file_name
  1784.  
  1785.    if tex_log_file_name <> '' then    -- a current log file exists
  1786.      if tex_file_in_ring(tex_log_file_name) then   -- loaded?
  1787.         -- can there still be errors in it?
  1788.         res = ( tex_log_file_line < tex_log_file_last )
  1789.      else
  1790.         res = 1
  1791.      endif  -- file in ring
  1792.    else
  1793.       res = 0
  1794.    endif -- current log file exists
  1795. return res
  1796.  
  1797. -----------------------------------------------------------------------------
  1798. -- Determine whether there is a "current" log file.
  1799. -- Returns 1 if so.
  1800.  
  1801. defproc tex_current_log
  1802.    universal tex_log_file_name
  1803. return tex_log_file_name <> ''
  1804.  
  1805. -----------------------------------------------------------------------------
  1806. --  Read LOG file and find errors in source code
  1807.  
  1808. defproc tex_find_errors
  1809.     universal  tex_log_file_line,
  1810.                tex_log_file_curr,
  1811.                tex_log_file_last,
  1812.                tex_log_file_name,
  1813.                tex_error_fname,
  1814.                name_count,
  1815.                par_count,
  1816.                EPM_utility_array_ID,
  1817.                app_hini,
  1818.                tex_debug
  1819.  
  1820.     empty = ''
  1821.     getfileid tex_return_to_fid
  1822.  
  1823.     tex_parse_filename(tex_log_file_name,dr,dir,stem,ext)
  1824.  
  1825.     if tex_file_in_ring(tex_log_file_name) = 1 then
  1826.         getfileid log_fid,tex_log_file_name
  1827.         activatefile log_fid
  1828.     else
  1829.         if not exist(tex_log_file_name) then
  1830.            call WinMessageBox(TEX_LOCERR_TITLE, TEX_L_LOG_STRING||
  1831.                         tex_log_file_name||TEX_NOTFOUND_STRING,
  1832.                         MB_OK+MB_WARNING+MB_MOVEABLE)
  1833.            -- clear the current log file name
  1834.            tex_log_file_name = ''
  1835.            call setprofile(app_hini, TEX_APP, 'LOGFILE', '')
  1836.            RETURN
  1837.         endif
  1838.         'edit /d /r' tex_log_file_name
  1839.         getfileid log_fid
  1840.         tex_error_fname = dr||dir||stem||'.tex'  -- ?
  1841.         call tex_parse_init()
  1842.     endif
  1843.     call tex_cd()
  1844.  
  1845.     do while (tex_log_file_line < tex_log_file_last)
  1846.  
  1847.       getline line, tex_log_file_line
  1848.  
  1849.       if leftstr(line,1) = '!' then
  1850.           -- memorize line number of the current error
  1851.           tex_log_file_curr = tex_log_file_line
  1852.           parse value line with '!'error_msg
  1853.           -- catch VTeX PostScript errors
  1854.           if word(error_msg, 1) <> 'PostScript' then
  1855.              -- search for line containing line number of error;
  1856.              -- if none is present, we must not run over the end of the file;
  1857.              -- better: realise this situation before -- how?
  1858.              do forever
  1859.                  tex_log_file_line = tex_log_file_line + 1
  1860.                  if tex_log_file_line > tex_log_file_last then leave endif
  1861.                  getline line, tex_log_file_line
  1862.                  if (leftstr(line,1) = 'l') or (leftstr(line,1) = '!')  then
  1863.                     leave
  1864.                  endif
  1865.              enddo
  1866.           endif
  1867. -- The message:
  1868.           parse value line with 'l.' linenum contexttext
  1869.           if word(error_msg, 1) = 'PostScript' then
  1870.              sayerror error_msg
  1871.              linenum = 'unknown'
  1872.           elseif isnum(linenum) then 
  1873.              -- try ordinary message format
  1874.              sayerror error_msg': 'contexttext
  1875.           else 
  1876.              -- try VTeX's format
  1877.              parse value line with 'l.' linenum '.' junk '(' vfilename ')'
  1878.              if isnum(linenum) and isnum(junk) and vfilename <> '' and (tex_log_file_line < tex_log_file_last) then
  1879.                 getline vline, tex_log_file_line+1
  1880.                 parse value vline with '> ' contexttext
  1881.                 sayerror error_msg': 'contexttext
  1882.              else
  1883.                 -- no success, either
  1884.                 linenum = 'unknown'
  1885.                 sayerror TEX_NOLOC_STRING||tex_error_fname
  1886.              endif
  1887.           endif
  1888. -- Where is the error?
  1889.           if  not isnum(linenum) then
  1890.               -- position of error cannot be determined,
  1891.               -- so we stay in the log file:
  1892.               .line = tex_log_file_curr
  1893.           elseif pos('.___',tex_error_fname) then 
  1894.               -- A marked region has been processed; 
  1895.               -- don't edit the temporary file!
  1896.               -- Stay on the error message in the .log file:
  1897.               .line = tex_log_file_line
  1898.           elseif tex_file_in_ring(tex_error_fname) = 1 then
  1899.               -- The file is already in the editor.
  1900.               getfileid tex_error_fid,tex_error_fname
  1901.               activatefile tex_error_fid
  1902.               if tex_debug > 1 then sayerror 'next file: 'tex_error_fname endif
  1903.           else
  1904.               -- This file should exist since we 'just' compiled it.
  1905.               'edit /d' tex_error_fname
  1906.               if tex_debug > 1 then sayerror 'next file: 'tex_error_fname endif
  1907.           endif
  1908. -- How to proceed?
  1909.           if not isnum(linenum) then
  1910.               -- Procced with line after the error message:
  1911.               tex_log_file_line = tex_log_file_curr + 1
  1912.               -- *** possible bug, perhaps ... +2 ?
  1913.           elseif pos('.___',tex_error_fname) then 
  1914.               -- proceed with next line
  1915.               tex_log_file_line = tex_log_file_line + 1
  1916.           elseif linenum > .last then
  1917.              -- Don't run over the last line, show log file instead
  1918.              activatefile log_fid
  1919.              .line = tex_log_file_curr
  1920.              sayerror TEX_ERRERR_STRING||tex_error_fname
  1921.           else
  1922.              -- OK, proceed and show the error in the source code:
  1923.              getline errorline, linenum
  1924.              tex_log_file_line = tex_log_file_line + 1
  1925.              if length(contexttext) > 4 then
  1926.                  chopum = 4
  1927.              else
  1928.                  chopum = 1
  1929.              endif
  1930.              col1 = pos( substr(contexttext,chopum), errorline)
  1931.              col2 = col1 + length(contexttext) - chopum + 1
  1932.              .line = linenum
  1933.              .col  = col2
  1934.              'PostMe tex_circleit '||col1
  1935.           endif
  1936.           RETURN
  1937.       else    /* This is not a line starting with '!' */
  1938.  
  1939.           do while not ( line = '')
  1940.  
  1941.               if tex_debug > 2 then sayerror 'line='line; endif
  1942.               left_par =  pos('(',line)
  1943.               right_par = pos(')',line)
  1944.               if tex_debug > 2 then sayerror 'left_par='left_par'  right_par='right_par; endif
  1945. -- EPM5 can only handle lines of 255 chars anyway, so make them 256 if the
  1946. -- are 0 to simplify things a bit.
  1947.               if left_par = 0 then left_par = 256 endif
  1948.               if right_par = 0 then right_par = 256 endif
  1949.  
  1950.               if (right_par < left_par) then
  1951.                   par_count = par_count - 1
  1952.                   if tex_debug > 2 then sayerror 'par_count (decreased) ='par_count; endif
  1953.                   if par_count = 0 then
  1954.                       if tex_debug > 2 then sayerror 'Erasing name 'name_count' from array'; endif
  1955.                       do_array 2, EPM_utility_array_ID, 'tex_fname.'name_count, empty
  1956.                       do_array 2, EPM_utility_array_ID, 'tex_par.'name_count, empty
  1957.                       name_count = name_count - 1
  1958. -- name_count will be 0 when we are finished
  1959.                       if name_count > 0 then
  1960.                           do_array 3, EPM_utility_array_ID, 'tex_fname.'name_count, tex_error_fname
  1961.                           do_array 3, EPM_utility_array_ID, 'tex_par.'name_count, par_count
  1962.                           if tex_debug > 2 then sayerror 'Got 'tex_error_fname'('name_count') and par_count='par_count; endif
  1963.                       else
  1964.                           if tex_debug > 2 then sayerror 'name_count = 0'; endif
  1965.                       endif
  1966.                   endif
  1967.                   if tex_debug > 2 then sayerror 'line=   'line; endif
  1968.                   line = substr(line,right_par+1)
  1969.                   if tex_debug > 2 then sayerror 'newline='line; endif
  1970.               else
  1971.                   if not (left_par = 256) then
  1972.                       line = substr(line,left_par+1)
  1973.                       if tex_debug > 1  then
  1974.                          sayerror 'searching for filename in:'line
  1975.                       endif
  1976.                       if tex_extract_fname(line,dr,dir) = 0 then
  1977.                           par_count = par_count + 1
  1978.                           if tex_debug > 2 then sayerror 'par_count (increased) ='par_count; endif
  1979.                       else
  1980.                           par_count = 1
  1981.                           if tex_debug > 2 then sayerror 'par_count set to 1'; endif
  1982.                       endif
  1983.                   else
  1984.                       line = ''
  1985.                   endif
  1986.               endif
  1987.           enddo  /*  while not (line='')  */
  1988.           tex_log_file_line = tex_log_file_line + 1
  1989.       endif /* line starts with ! */
  1990.  
  1991.     enddo     /*  while (tex_log_file_line < tex_log_file_last)  */
  1992.  
  1993.     if not (tex_log_file_line < tex_log_file_last) then
  1994.         activatefile tex_return_to_fid
  1995.         sayerror TEX_NOERRORS_STRING
  1996.     endif
  1997.  
  1998. -----------------------------------------------------------------------------
  1999. -- executed (if requested) after the above routine returns to the user
  2000. defc tex_circleit
  2001.    circleit 3, .line, arg(1), .col, LIGHT_RED
  2002.    -- thick light-red circle; well visible,
  2003.    -- except on red background, which is unlikely
  2004. return
  2005.  
  2006. -----------------------------------------------------------------------------
  2007. -- we are in the log file and initialize the error parsing facility
  2008. defproc tex_parse_init
  2009.    universal tex_log_file_line,
  2010.              tex_log_file_curr,
  2011.              tex_log_file_last,
  2012.              name_count,
  2013.              par_count
  2014.  
  2015.    tex_log_file_line = 3
  2016.    tex_log_file_curr = 3
  2017.    tex_log_file_last = .last
  2018.    name_count = 0
  2019.    par_count = 1
  2020. return
  2021.  
  2022. -----------------------------------------------------------------------------
  2023. -- This routine is called by tex_find_errors .
  2024. -- Its 1st argument is a part of a line from the log file, starting after a '('.
  2025. -- It determines whether or not the text following the '(' is a filename.
  2026. -- If it is, tex_error_fname is changed to that name, and the routine
  2027. -- returns 1.  Otherwise, a 0 is returned.
  2028. --
  2029. -- The logic goes like this:
  2030. --  1) search for '(', ')' and ' '; throw away what follows
  2031. --  2) make sure there is a '.' in the remaining string
  2032. --  3) parse it into pieces before '.' and after '.'
  2033. --  4) make sure that the first part is not empty 
  2034. --  5) the name is fully qualified and placed in
  2035. --     tex_error_fname, and is also put into an array.
  2036. --  6) take name out of "line"
  2037. --  7) return
  2038.  
  2039. defproc tex_extract_fname(var line, dr, dir)
  2040.     universal  tex_error_fname,
  2041.                par_count,
  2042.                name_count,
  2043.                EPM_utility_array_ID,
  2044.                tex_debug 
  2045.  
  2046.     flag = 0
  2047.     tmp = line
  2048.     -- truncate before a possible space, '(' or ')':
  2049.     ppos = pos(' ', tmp)
  2050.     if ppos > 0 then
  2051.        tmp = leftstr(tmp, (ppos-1))
  2052.     endif
  2053.     ppos = pos('(', tmp)
  2054.     if ppos > 0 then
  2055.        tmp = leftstr(tmp, (ppos-1))
  2056.     endif
  2057.     ppos = pos(')', tmp)
  2058.     if ppos > 0 then
  2059.        tmp = leftstr(tmp, (ppos-1))
  2060.     endif
  2061.     -- now make sure there is still a '.' in it:
  2062.     if  pos('.', tmp) then
  2063.         -- break it into pieces before and after the '.'
  2064.         parse value tmp with tmp1 '.' tmp2
  2065.         if tmp1 <> '' then -- yes, it was a filename
  2066.             if tmp2 = '' then -- take tmp1 only
  2067.                tmpname = tmp1
  2068.             else
  2069.                tmpname = tmp1||'.'||tmp2
  2070.             endif
  2071. --              Translate from Unix-style to OS/2-style file names
  2072.                 tex_error_fname = translate(tmpname,'\','/')
  2073. --  Now, name the name fully qualified
  2074. --              If only a stem.ext
  2075.                 if lastpos('\',tex_error_fname) = 0 then
  2076.                     tex_error_fname = dr||dir||tex_error_fname
  2077.                     if tex_debug > 2 then sayerror 'tex_error_fname (again1)='tex_error_fname; endif
  2078.                 else
  2079. --                  if no drive letter
  2080.                     if leftstr(tex_error_fname,1) = '\' then
  2081.                         tex_error_fname = dr||tex_error_fname
  2082.                         if tex_debug > 2 then sayerror 'tex_error_fname (again2)='tex_error_fname; endif
  2083.                     endif
  2084.                 endif
  2085.                 name_count = name_count + 1
  2086.                 if tex_debug > 2 then  sayerror 'Putting 'tex_error_fname' on stack with par_count='par_count' at position 'name_count; endif
  2087.                 do_array 2, EPM_utility_array_ID, 'tex_fname.'name_count, tex_error_fname
  2088.                 do_array 2, EPM_utility_array_ID, 'tex_par.'name_count, par_count
  2089.                 flag = 1
  2090. -- Take the filename out of line for next loop
  2091. ;                line = substr(line,pos(tmpname,line)+length(tmpname))
  2092.                 line = substr(line,pos(tmp,line)+length(tmp)) -- *** v1.1
  2093.         endif
  2094.     endif
  2095.  
  2096.     return flag
  2097.  
  2098. -----------------------------------------------------------------------------
  2099. /*
  2100. -- A procedure to expand environment variables in user defined constants
  2101. --
  2102. -- searches for $variable: in user defined constants and expands 'variable'
  2103. -- if found
  2104.  
  2105. defproc Expand_Env(Input)
  2106.  
  2107.    Parse Value Input with Lead_Var '$' Env_Var ':' Trail_Var
  2108.  
  2109.    if Env_Var <> '' & LastPos(':',Input) > Pos('$',Input) then
  2110.       Output = Lead_Var || Get_Env(Env_Var) || Trail_Var
  2111.    else
  2112.       Output = Input
  2113.    endif
  2114.  
  2115. return Output
  2116. */
  2117.  
  2118. -----------------------------------------------------------------------------
  2119. -- A procedure to check whether the current file is a TeX document
  2120.  
  2121. defproc tex_is_doc
  2122.    universal app_hini
  2123.  
  2124. types = queryprofile( app_hini, TEX_APP, 'DOCTYPES')
  2125. return wordpos(filetype(), types)
  2126.  
  2127. -----------------------------------------------------------------------------
  2128. -- A procedure to check whether the current file is a TeX style file
  2129.  
  2130. defproc tex_is_style
  2131.    universal app_hini
  2132.  
  2133. types = queryprofile( app_hini, TEX_APP, 'STYLETYPES')
  2134. return wordpos(filetype(), types)
  2135.  
  2136. ----------------------------------------------------------------------------
  2137. -- A procedure to check whether the current file is a TeX file
  2138.  
  2139. defproc tex_is_file
  2140.    universal app_hini
  2141.  
  2142. doctypes   = queryprofile( app_hini, TEX_APP, 'DOCTYPES')
  2143. styletypes = queryprofile( app_hini, TEX_APP, 'STYLETYPES')
  2144. return wordpos(filetype(), doctypes styletypes)
  2145.  
  2146. -----------------------------------------------------------------------------
  2147. -- Substitute the arg specifieres %**N and %**F within a command string
  2148.  
  2149. defproc tex_makecmd(command, fname, ext)
  2150. -- we perform the following substitutions:
  2151. -- %**N   ->  filename without extension
  2152. -- %**F   ->  filename with extension
  2153.  
  2154.     do forever
  2155.        posi=pos('%**N', command)
  2156.        if posi then
  2157.           command=delstr(command, posi, 4)
  2158.           command = insertstr(fname, command, (posi-1))
  2159.        else
  2160.           leave
  2161.        endif
  2162.     enddo
  2163.     do forever
  2164.        posi=pos('%**F', command)
  2165.        if posi then
  2166.           command=delstr(command, posi, 4)
  2167.           command = insertstr(fname'.'ext, command, (posi-1))
  2168.        else
  2169.           leave
  2170.        endif
  2171.     enddo
  2172.     return command
  2173.  
  2174. -----------------------------------------------------------------------------
  2175. -- check a variable from the INI file, return its value as 'ON' or 'OFF'
  2176.  
  2177. defproc tex_querysetting(name)
  2178.    universal app_hini
  2179.    if queryprofile(app_hini, TEX_APP, name) then
  2180.       return(TEX_ON_STRING)
  2181.    else
  2182.       return(TEX_OFF_STRING)
  2183.    endif
  2184. return
  2185.  
  2186. -----------------------------------------------------------------------------
  2187. -- toggle a variable from the INI file
  2188.  
  2189. defproc tex_togglesetting(name)
  2190.    universal app_hini
  2191.    if queryprofile(app_hini, TEX_APP, name) then
  2192.       call setprofile(app_hini, TEX_APP, name, '')
  2193.    else
  2194.       call setprofile(app_hini, TEX_APP, name, '1')
  2195.    endif
  2196. return
  2197.  
  2198. -----------------------------------------------------------------------------
  2199. -- Switch to the directory of the current file
  2200.  
  2201. defproc tex_cd
  2202.    universal tex_debug
  2203.  
  2204.    dirpos=lastpos('\',.filename)
  2205.    if dirpos>1 then
  2206.       dir = substr(.filename,1,dirpos-1)
  2207.       if lastpos(':', dir) = length(dir) then
  2208.          dir = dir || '\'
  2209.       endif
  2210.       if  tex_debug then
  2211.          sayerror 'cd 'dir
  2212.       endif
  2213.       call directory(dir)
  2214.    endif
  2215. return
  2216.  
  2217. -----------------------------------------------------------------------------
  2218. -- Pop up a warning about a command that crashed
  2219.  
  2220. defproc tex_cmderror(title)
  2221.    call WinMessageBox(title, TEX_CMDERR_STRING,
  2222.                       MB_OK+MB_ERROR+MB_MOVEABLE)
  2223. return
  2224.  
  2225. -----------------------------------------------------------------------------
  2226.  
  2227.  
  2228. /************************************/
  2229. /*                                  */
  2230. /*   The OS/2 related procedures    */
  2231. /*                                  */
  2232. /************************************/
  2233.  
  2234. defc tex_osshell
  2235.  
  2236.    call tex_cd()
  2237.    title = 'Shell - 'directory()
  2238.    command = 'start "'title'" /F /K MODE CO80, 40'
  2239.    command
  2240.    if rc <> 0 then
  2241.      sayerror command || TEX_CMDFAIL_STRING || rc
  2242.      call tex_cmderror(TEX_OSSHELL_TITLE)
  2243.    endif
  2244. return
  2245.  
  2246.  
  2247. defc tex_fm -- 'fm' means 'file manager' :-)
  2248.  
  2249.    call tex_cd()
  2250.    command = 'start /F /C /MIN TFEFM.CMD'
  2251.    command
  2252.    if rc <> 0 then
  2253.      sayerror command || TEX_CMDFAIL_STRING || rc
  2254.      call tex_cmderror(TEX_FOLDER_TITLE)
  2255.    endif
  2256. return
  2257.  
  2258.  
  2259. /********************************************************/
  2260. /*                                                      */
  2261. /*   All the procedures to change/show the settings     */
  2262. /*                                                      */
  2263. /********************************************************/
  2264.  
  2265. defc tex_debuglevel
  2266.    universal tex_debug
  2267.    if arg(1) = '' then
  2268.       sayerror 'TeX_debuglevel: 'tex_debug
  2269.    else
  2270.       tex_debug = arg(1)
  2271.    endif
  2272.  
  2273.  
  2274. compile if TEXFEPRO and WANT_TEX_MENU
  2275.  
  2276. defproc check_tex_master --  check whether master file support is enabled
  2277.    universal app_hini
  2278.    if queryprofile(app_hini, TEX_APP, 'TEX_MASTERFILE') then
  2279.       return 1
  2280.    else
  2281.       return 0
  2282.    endif
  2283. return
  2284.  
  2285. defc tex_master_file_support
  2286.    call tex_togglesetting('TEX_MASTERFILE')
  2287. return
  2288.  
  2289. compile endif /* TEXFEPRO and WANT_TEX_MENU */
  2290.  
  2291.  
  2292. defproc tex_editsetting(name, defaultvalue, title)
  2293.    universal app_hini
  2294.    
  2295.    setting = queryprofile(app_hini, TEX_APP, name)
  2296.    do forever
  2297.      sbuf = entrybox(title, 
  2298.                      TEX_SOPT_BUTTONS,
  2299.                      setting,60,80,
  2300.                      atoi(1) ||            -- default button # 
  2301.                      atoi(0) ||            -- help panel ID (0 for no help)
  2302.                      gethwnd(APP_HANDLE) ||\0) 
  2303.                                            -- prompt
  2304.      button = asc(leftstr(sbuf,1))
  2305.      if button=3 or button=0 then LEAVE; endif -- Cancel or closed otherwise
  2306.      if button=2 then                          -- Use std. setting
  2307.         setting = defaultvalue
  2308.      else                                      -- OK
  2309.         EOS = pos(\0,sbuf,2)    -- CHR(0) signifies End Of String
  2310.         setting = substr(sbuf,2,EOS-2)
  2311.         call setprofile(app_hini, TEX_APP, name, setting)
  2312.         LEAVE
  2313.      endif
  2314.    enddo
  2315. return
  2316.  
  2317.  
  2318. defproc tex_set_data(id) -- change user settings
  2319.    universal app_hini
  2320. compile if EXTENDED_LATEX_ASSIST
  2321.    universal TeX_Margin
  2322. compile endif
  2323.    
  2324.    if id='1' then -- document file types
  2325.       call tex_editsetting('DOCTYPES', TEX_DOCTYPES_D, TEX_DOCTYPES_STRING)
  2326.  
  2327.    elseif id='2' then -- style file types
  2328.       call tex_editsetting('STYLETYPES', TEX_STYLETYPES_D, TEX_STYLETYPES_STRING)
  2329. /*
  2330.    elseif id='3' then -- auxiliary file types
  2331.       call tex_editsetting('FILETYPES', TEX_FILETYPES_D, TEX_FILETYPES_STRING)
  2332. */
  2333.    elseif id='3' then -- accelerator keys
  2334.       call tex_togglesetting('TEX_KEYS')
  2335.  
  2336.    elseif id='4' then -- highlighting
  2337.       call tex_togglesetting('TEX_SYNTAXHILITE')
  2338.  
  2339.    elseif id='5' then -- default format
  2340.       call tex_editsetting('DEFAULT_FORMAT', TEX_DEFAULT_FORMAT_D, TEX_FORMAT_TITLE)
  2341.  
  2342.    elseif id='6' then -- master file support
  2343.       call tex_togglesetting('TEX_MASTERFILE')
  2344.       
  2345. compile if EXTENDED_LATEX_ASSIST
  2346.    elseif id='7' then -- TeX margin
  2347.       ma = strip(entrybox(TEX_MA_TITLE, TEX_EC_BUTTONS,
  2348.                             TeX_Margin,60,40))
  2349.       if (ma <> '') and isnum(ma) then
  2350.          call setprofile(app_hini, TEX_APP, 'MARGIN', ma)
  2351.          TeX_Margin = ma
  2352.          -- We do not only save the value in the INI file, 
  2353.          -- we also save it in a universal variable, because
  2354.          -- this value must be read each time the <space> or 
  2355.          -- <enter> key is pressed.
  2356.       endif
  2357. compile endif
  2358.  
  2359. compile if defined (vtex)
  2360.    elseif id='7' then -- vtex options for pdf mode
  2361.       call tex_editsetting('PDF_OPTIONS', TEX_PDF_OPTIONS_D, TEX_PDFOPTIONS_STRING)
  2362.  
  2363.    elseif id='8' then -- vtex options for ps mode
  2364.       call tex_editsetting('PS_OPTIONS', TEX_PS_OPTIONS_D, TEX_PSOPTIONS_STRING)
  2365.  
  2366.    elseif id='9' then -- PDF preview
  2367.       call tex_editsetting('VIEWPDF_CMD', TEX_VIEWPDF_D, TEX_PDFV_STRING)
  2368.       
  2369.    elseif id='10' then -- PS preview
  2370.       call tex_editsetting('VIEWPS_CMD', TEX_VIEWPS_D, TEX_PSV_STRING)
  2371. compile endif
  2372.  
  2373.    endif
  2374. return /* tex_set_data() */
  2375.  
  2376.  
  2377. defc texfe_settings_window
  2378. -- contributed by Wonkoo Kim (wkim+@pitt.edu), November 14, 1997;
  2379.  
  2380.      universal app_hini
  2381. compile if EXTENDED_LATEX_ASSIST
  2382.      universal TeX_Margin
  2383. compile endif
  2384.  
  2385.      if arg(1) = '' then
  2386.      id = 1
  2387.      else
  2388.      id = arg(1)
  2389.      endif
  2390.  
  2391.      menu_title = TEX_CONF_TITLE
  2392.      settings = ''
  2393.      no = 1
  2394.      settings = settings||\1no||' 'TEX_S1' = '||queryprofile(app_hini, TEX_APP, 'DOCTYPES')
  2395.      no = no + 1
  2396.      settings = settings||\1no||' 'TEX_S2' = '||queryprofile(app_hini, TEX_APP, 'STYLETYPES')
  2397. /*
  2398.      no = no + 1
  2399.      settings = settings||\1no||' 'TEX_S3' = '||queryprofile(app_hini, TEX_APP, 'FILETYPES')
  2400. */     
  2401.      no = no + 1
  2402.      settings = settings||\1no||' 'TEX_S3' = '||tex_querysetting('TEX_KEYS')
  2403.      no = no + 1
  2404.      settings = settings||\1no||' 'TEX_S4' = '||tex_querysetting('TEX_SYNTAXHILITE')
  2405.      no = no + 1 
  2406.      settings = settings||\1no||' 'TEX_S5' = '||queryprofile(app_hini, TEX_APP, 'DEFAULT_FORMAT')
  2407.      no = no + 1
  2408.      settings = settings||\1no||' 'TEX_S6' = '||tex_querysetting('TEX_MASTERFILE')
  2409. compile if EXTENDED_LATEX_ASSIST
  2410.      no = no + 1
  2411.      settings = settings||\1no||' 'TEX_S7' = '||TeX_Margin
  2412. compile endif
  2413. compile if defined (vtex)
  2414.      no = no + 1 
  2415.      settings = settings||\1no||' 'TEX_S7' = '||queryprofile(app_hini, TEX_APP, 'PDF_OPTIONS')
  2416.      no = no + 1 
  2417.      settings = settings||\1no||' 'TEX_S8' = '||queryprofile(app_hini, TEX_APP, 'PS_OPTIONS')
  2418.      no = no + 1 
  2419.      settings = settings||\1no||' 'TEX_S9' = '||queryprofile(app_hini, TEX_APP, 'VIEWPDF_CMD')
  2420.      no = no + 1 
  2421.      settings = settings||\1no||' 'TEX_S10' = '||queryprofile(app_hini, TEX_APP, 'VIEWPS_CMD')
  2422. compile endif
  2423. -- 
  2424.      y = min(25,.windowheight+2)
  2425.      x = min(15,.windowwidth*.3)
  2426.      h = min(8,.windowheight*.75)
  2427.      w = min(70,.windowwidth)
  2428.      sbuf = listbox(menu_title, settings,
  2429.         TEX_MO_BUTTONS,
  2430.      y,x,h,w, -- row,col,height,width
  2431.      gethwnd(APP_HANDLE) ||
  2432.      atoi(id) ||    -- initial item # selected (start from 1)
  2433.      atoi(1) ||    -- default button # selected (start from 1)
  2434.      atoi(0) ||    -- help panel ID (0 for no help)
  2435.      ''\0);          -- prompt
  2436.      button = asc(leftstr(sbuf,1))
  2437.      if button = 1 then
  2438.      EOS = pos(\0, sbuf, 2)          -- CHR(0) signifies End Of String
  2439.      select = substr(sbuf, 2, EOS-2)
  2440.      else
  2441.      return
  2442.      endif
  2443.      -- 'TeX_'||word(select,2)
  2444.      call tex_set_data( word(select,1) )
  2445.      'texfe_settings_window' word(select,1)
  2446.  
  2447. /* Finis */
  2448.  
  2449.