home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / editor / epmtools / cstepm / latexmnu.e < prev    next >
Encoding:
Text File  |  1993-03-25  |  13.5 KB  |  298 lines

  1. compile if not defined(SMALL)  -- If SMALL not defined, then being separately compiled
  2.  define INCLUDING_FILE = 'LATEXMNU.E'
  3. const
  4.    tryinclude 'MYCNF.E'        -- the user's configuration customizations.
  5.  
  6.  compile if not defined(SITE_CONFIG)
  7.     const SITE_CONFIG = 'SITECNF.E'
  8.  compile endif
  9.  compile if SITE_CONFIG
  10.     tryinclude SITE_CONFIG
  11.  compile endif
  12. compile endif
  13.  
  14. const
  15. compile if not defined(WANT_DYNAMIC_PROMPTS)
  16.    WANT_DYNAMIC_PROMPTS = 1
  17. compile endif
  18. compile if EVERSION < '5.21'
  19.    TILDE_CHAR = ''
  20. compile else
  21.    TILDE_CHAR = '~'
  22. compile endif
  23.    AF_CHAR        =   1   -- key style constants (from STDCONST.E)
  24.    AF_ALT         =  32
  25.  
  26. ;  my_ADDRESS = 'Larry Margolis\\P.O.\ Box 218\\Yorktown Heights, NY  11287'
  27. ;  my_SIGNATURE = 'Lawrence A.\ Margolis\\EPM Guru'
  28.  
  29. const  -- Text defined separately, for easier NLS translation
  30.    LATEX_BAR__MSG =      TILDE_CHAR'LaTeX '
  31.      LIST_ITEM_MENU__MSG = '~List item'
  32.      QUOTE_MENU__MSG =     '~Quote'
  33.      QUOTATION_MENU__MSG = '~Quotation'
  34.      CENTER_MENU__MSG =    '~Center'
  35.      UNDERLINE_MENU__MSG = 'U~nderline'
  36.      OLIST_MENU__MSG =     '~Enumerated list'
  37.      ULIST_MENU__MSG =     '~Itemized list'
  38.      DLIST_MENU__MSG =     '~Description list'
  39.      MATH_MENU__MSG =      '~Math'
  40.      DMATH_MENU__MSG =     '~Displaymath'
  41.      EQN_MENU__MSG =       '~Equation'
  42.      FIGURE_MENU__MSG =    '~Figure'
  43.      TABLE_MENU__MSG =     '~Table'
  44.      FOOTNOTE_MENU__MSG =  '~Footnote'
  45.      HEADS_MENU__MSG =     '~Sections'
  46.        HEAD0_MENU__MSG =   '~Part'
  47.        HEAD1_MENU__MSG =   '~Chapter'
  48.        HEAD2_MENU__MSG =   '~Section'
  49.        HEAD3_MENU__MSG =   'S~ubsection'
  50.        HEAD4_MENU__MSG =   'Su~bsubsection'
  51.        HEAD5_MENU__MSG =   'P~aragraph'
  52.        HEAD6_MENU__MSG =   'Subpa~ragraph'
  53.      EM_MENU__MSG =        '~Emphasize phrase'
  54.      TYPES_MENU__MSG =     '~Typestyles'
  55.        TYPE_BF_MENU__MSG = '~Bold'
  56.        TYPE_SF_MENU__MSG = '~Sans serif'
  57.        TYPE_SL_MENU__MSG = 'S~lanted'
  58.        TYPE_SC_MENU__MSG = 'S~mall caps'
  59.        TYPE_TT_MENU__MSG = '~Typewriter type'
  60.        TYPE_RM_MENU__MSG = '~Roman'
  61.        TYPE_IT_MENU__MSG = '~Italic'
  62.      DOC_MENU__MSG =       'Docu~ments'
  63.        SIMPLE_MENU__MSG =   '~Simple'
  64.        LETTER_MENU__MSG =   '~Letter'
  65.  
  66. compile if WANT_DYNAMIC_PROMPTS
  67.    LATEX_BARP__MSG =      \1'Insert LaTeX commands'
  68.      LIST_ITEM_MENUP__MSG = \1'Insert \item tag after current line'
  69.      QUOTE_MENUP__MSG =     \1'Insert quote environment around mark or after current line'
  70.      QUOTATION_MENUP__MSG = \1'Insert quotation environment after current line'
  71.      CENTER_MENUP__MSG =    \1'Insert center command after current line'
  72.      UNDERLINE_MENUP__MSG = \1'Insert underline command around block or char. mark, or current word'
  73.      OLIST_MENUP__MSG =     \1'Create an enumerated list'
  74.      ULIST_MENUP__MSG =     \1'Create an itemized (bulleted) list'
  75.      DLIST_MENUP__MSG =     \1'Create a description list'
  76.      MATH_MENUP__MSG =      \1'Create an inline mathematical formula'
  77.      DMATH_MENUP__MSG =     \1'Create a separatly-displayed mathematical formula'
  78.      EQN_MENUP__MSG =       \1'Create a numbered mathematical formula'
  79.      FIGURE_MENUP__MSG =    \1'Create a figure'
  80.      TABLE_MENUP__MSG =     \1'Create a table'
  81.      FOOTNOTE_MENUP__MSG =  \1'Create a footnote'
  82.      HEADS_MENUP__MSG =     \1'Insert sectioning commands'
  83.        HEADx_MENUP__MSG =     \1'Insert the indicated sectioning command'
  84.      EM_MENUP__MSG =        \1'Emphasize a phrase - block or char. mark, or current word'
  85.      TYPES_MENUP__MSG =     \1'Change the typestyle of a phrase - block or char. mark, or current word'
  86.        TYPE_x_MENUP__MSG =  \1'Change block or char. mark, or current word, to indicated typestyle'
  87.      DOC_MENUP__MSG =       \1'Create a document'
  88.        SIMPLE_MENUP__MSG =    \1'Create a simple document'
  89.        LETTER_MENUP__MSG =    \1'Create a Bookmaster User Document'
  90. compile else
  91.    LATEX_BARP__MSG =      ''
  92.      LIST_ITEM_MENUP__MSG = ''
  93.      QUOTE_MENUP__MSG =     ''
  94.      QUOTATION_MENUP__MSG = ''
  95.      CENTER_MENUP__MSG =    ''
  96.      UNDERLINE_MENUP__MSG = ''
  97.      OLIST_MENUP__MSG =     ''
  98.      ULIST_MENUP__MSG =     ''
  99.      DLIST_MENUP__MSG =     ''
  100.      MATH_MENUP__MSG =      ''
  101.      DMATH_MENUP__MSG =     ''
  102.      EQN_MENUP__MSG =       ''
  103.      FIGURE_MENUP__MSG =    ''
  104.      TABLE_MENUP__MSG =     ''
  105.      FOOTNOTE_MENUP__MSG =  ''
  106.      HEADS_MENUP__MSG =     ''
  107.        HEADx_MENUP__MSG =   ''
  108.      EM_MENUP__MSG =        ''
  109.      TYPES_MENUP__MSG =     ''
  110.        TYPE_x_MENUP__MSG =  ''
  111.      DOC_MENUP__MSG =      ''
  112.        SIMPLE_MENUP__MSG = ''
  113.        LETTER_MENUP__MSG = ''
  114. compile endif  -- WANT_DYNAMIC_PROMPTS
  115.  
  116. definit
  117.    universal defaultmenu, activemenu
  118.    universal activeaccel
  119.    universal LaTeX_cmds_menu_flag
  120.    deletemenu defaultmenu, 6, 0, 0  -- delete the existing Help menu (we want it to stay at the right)
  121.  
  122.    buildsubmenu defaultmenu, 39, LATEX_BAR__MSG, LATEX_BARP__MSG, 0, 0
  123.      buildmenuitem defaultmenu,   39, 3901, LIST_ITEM_MENU__MSG,     'LaTeX_IL 1 \item 'LIST_ITEM_MENUP__MSG, 0, 0
  124.      buildmenuitem defaultmenu,   39, 3902, QUOTE_MENU__MSG,         'LaTeX_quote'QUOTE_MENUP__MSG, 0, 0
  125.      buildmenuitem defaultmenu,   39, 3903, QUOTATION_MENU__MSG,     'LaTeX_IML /\begin{quotation}/  /\end{quotation}'QUOTATION_MENUP__MSG, 0, 0
  126.      buildmenuitem defaultmenu,   39, 3904, CENTER_MENU__MSG,        'LaTeX_IML /\begin{center}/  /\end{center}'CENTER_MENUP__MSG, 0, 0
  127.      buildmenuitem defaultmenu,   39, 3905, UNDERLINE_MENU__MSG,     'LaTeX_UL'UNDERLINE_MENUP__MSG, 0, 0
  128.      buildmenuitem defaultmenu,   39, 3906, \0,                      '',      4, 0
  129.      buildmenuitem defaultmenu,   39, 3910, OLIST_MENU__MSG,         'LaTeX_IML /\begin{enumerate}/  \item /end{enumerate}'OLIST_MENUP__MSG, 0, 0
  130.      buildmenuitem defaultmenu,   39, 3911, ULIST_MENU__MSG,         'LaTeX_IML /\begin{itemize}/  \item /end{itemize}'ULIST_MENUP__MSG, 0, 0
  131.      buildmenuitem defaultmenu,   39, 3912, DLIST_MENU__MSG,         'LaTeX_IML /\begin{description}/  \item []/end{description}'DLIST_MENUP__MSG, 0, 0
  132.      buildmenuitem defaultmenu,   39, 3913, \0,                      '',      4, 0
  133.      buildmenuitem defaultmenu,   39, 3920, MATH_MENU__MSG,          'LaTeX_IT \begin{math} ~\end{math}'MATH_MENUP__MSG, 0, 0
  134.      buildmenuitem defaultmenu,   39, 3921, DMATH_MENU__MSG,         'LaTeX_IML /\begin{displaymath}/  /\end{displaymath}'DMATH_MENUP__MSG, 0, 0
  135.      buildmenuitem defaultmenu,   39, 3922, EQN_MENU__MSG,           'LaTeX_IML /\begin{equation}/  /\end{equation}'EQN_MENUP__MSG, 0, 0
  136.      buildmenuitem defaultmenu,   39, 3923, FIGURE_MENU__MSG,        'LaTeX_IML /\begin{figure}/  /  \caption{}/\end{figure}'FIGURE_MENUP__MSG, 0, 0
  137.      buildmenuitem defaultmenu,   39, 3924, TABLE_MENU__MSG,         'LaTeX_IML /\begin{table}/  /  \caption{}/\end{table}'TABLE_MENUP__MSG, 0, 0
  138.      buildmenuitem defaultmenu,   39, 3925, FOOTNOTE_MENU__MSG,      'LaTeX_IT \footnote{~}'FOOTNOTE_MENUP__MSG, 0, 0
  139.      buildmenuitem defaultmenu,   39, 3929, \0,                      '',      4, 0
  140.      buildmenuitem defaultmenu,   39, 3930, HEADS_MENU__MSG,         HEADS_MENUP__MSG, 17, 0
  141.        buildmenuitem defaultmenu, 39, 3931, HEAD0_MENU__MSG,         'LaTeX_IL 0 \part'HEADx_MENUP__MSG, 0, 0
  142.        buildmenuitem defaultmenu, 39, 3932, HEAD1_MENU__MSG,         'LaTeX_IL 0 \chapter'HEADx_MENUP__MSG, 0, 0
  143.        buildmenuitem defaultmenu, 39, 3933, HEAD2_MENU__MSG,         'LaTeX_IL 0 \section'HEADx_MENUP__MSG, 0, 0
  144.        buildmenuitem defaultmenu, 39, 3934, HEAD3_MENU__MSG,         'LaTeX_IL 0 \subsection'HEADx_MENUP__MSG, 0, 0
  145.        buildmenuitem defaultmenu, 39, 3935, HEAD4_MENU__MSG,         'LaTeX_IL 0 \subsubsection'HEADx_MENUP__MSG, 0, 0
  146.        buildmenuitem defaultmenu, 39, 3936, HEAD5_MENU__MSG,         'LaTeX_IL 0 \paragraph'HEADx_MENUP__MSG, 0, 0
  147.        buildmenuitem defaultmenu, 39, 3937, HEAD6_MENU__MSG,         'LaTeX_IL 0 \subparagraph'HEADx_MENUP__MSG, 32769, 0
  148.      buildmenuitem defaultmenu,   39, 3940, EM_MENU__MSG,            'LaTeX_EM em'EM_MENUP__MSG, 0, 0
  149.      buildmenuitem defaultmenu,   39, 3941, TYPES_MENU__MSG,         TYPES_MENUP__MSG, 17, 0
  150.        buildmenuitem defaultmenu, 39, 3942, TYPE_BF_MENU__MSG,         'LaTeX_EM bf'TYPE_x_MENUP__MSG, 0, 0
  151.        buildmenuitem defaultmenu, 39, 3943, TYPE_SF_MENU__MSG,         'LaTeX_EM sf'TYPE_x_MENUP__MSG, 0, 0
  152.        buildmenuitem defaultmenu, 39, 3944, TYPE_SL_MENU__MSG,         'LaTeX_EM sl'TYPE_x_MENUP__MSG, 0, 0
  153.        buildmenuitem defaultmenu, 39, 3945, TYPE_SC_MENU__MSG,         'LaTeX_EM sc'TYPE_x_MENUP__MSG, 0, 0
  154.        buildmenuitem defaultmenu, 39, 3946, TYPE_TT_MENU__MSG,         'LaTeX_EM tt'TYPE_x_MENUP__MSG, 0, 0
  155.        buildmenuitem defaultmenu, 39, 3947, TYPE_RM_MENU__MSG,         'LaTeX_EM rm'TYPE_x_MENUP__MSG, 0, 0
  156.        buildmenuitem defaultmenu, 39, 3948, TYPE_IT_MENU__MSG,         'LaTeX_EM it'TYPE_x_MENUP__MSG, 32769, 0
  157.      buildmenuitem defaultmenu,   39, 3960, DOC_MENU__MSG,           DOC_MENUP__MSG, 17, 0
  158.        buildmenuitem defaultmenu, 39, 3961, SIMPLE_MENU__MSG,        'SIMPLE_DOC'SIMPLE_MENUP__MSG, 0, 0
  159.        buildmenuitem defaultmenu, 39, 3962, LETTER_MENU__MSG,        'LETTER_DOC'LETTER_MENUP__MSG, 32769, 0
  160.  
  161.    call readd_help_menu()
  162.    LaTeX_cmds_menu_flag = 1
  163.  
  164.    buildacceltable activeaccel, 'dokey a+L', AF_CHAR+AF_ALT,    76, 3998  -- a+L
  165.    buildacceltable activeaccel, 'dokey a+L', AF_CHAR+AF_ALT,   108, 3999  -- a+l
  166.    activateacceltable activeaccel
  167.  
  168. defc LaTeX_IL = -- InsertLine
  169.    parse arg indent_flag rest
  170.    if indent_flag then
  171.       getline line
  172.       pref=leftstr(line, max(0, verify(line, ' '\9, 'N')-1))
  173.       insertline pref || rest, .line+1
  174.    else
  175.       insertline rest, .line+1
  176.    endif
  177.    '+1'
  178.    end_line
  179.  
  180. defc LaTeX_IT = -- InsertText
  181.    i_s = insert_state()
  182.    if not i_s then insert_toggle; endif
  183.    newtext = arg(1)
  184.    c = pos('~', newtext)
  185.    if c then
  186.       keyin leftstr(newtext, c-1)
  187.       cursor_line = .line; cursor_col = .col
  188.       keyin substr(newtext, c+1)
  189.       cursor_line; .col = cursor_col
  190.       call fixup_cursor()
  191.    else
  192.       keyin newtext
  193.       if not insert_state() then insert_toggle; endif  -- restore insert status
  194.    endif
  195.  
  196. defc LaTeX_quote = -- Prefix line with arg
  197.    mt = marktype()
  198.    if mt='' then
  199.       'LaTeX_IML /\begin{quote}/  /\end{quote}'
  200.    else
  201.       getfileid fid
  202.       getmark firstline,lastline,firstcol,lastcol,fileid
  203.       if fid<>fileid then
  204.          sayerror 'Wrong file - check mark'
  205.          return
  206.       endif
  207.       if leftstr(mt,1)='L' then  -- Line mark
  208.          insertline '\end{quote}', lastline+1
  209.          insertline '\begin{quote}', firstline
  210.       else
  211.          call LaTeX_insert_tags('\begin{quote} ', '\end{quote} ')
  212.       endif
  213.    endif
  214.  
  215. defc LaTeX_IML = -- Insert Many Lines
  216.    getline line
  217.    pref=leftstr(line, max(0, verify(line, ' '\9, 'N')-1))
  218.    parse value strip(arg(1),'L') with delim 2 rest
  219.    nextline = .line+1
  220.    do while rest <> ''
  221.       parse value rest with line (delim) rest
  222.       insertline pref || line, nextline
  223.       nextline = nextline + 1
  224.    enddo
  225.    '+2'
  226.    end_line
  227.    r2 = rightstr(textline(.line), 2)
  228.    if r2='[]' | r2='{}' then
  229.       left
  230.       if not insert_state() then insert_toggle; call fixup_cursor(); endif
  231.    endif
  232.  
  233. defc LaTeX_em
  234.    call LaTeX_insert_tags('{\'arg(1)' ', '}')
  235.  
  236. defc LaTeX_ul
  237.    call LaTeX_insert_tags('\underline{', '}')
  238.  
  239. defproc LaTeX_insert_tags(start_tag, end_tag)
  240.    mt = marktype()
  241.    if pos(leftstr(mt,1), 'BC') then  -- Block or Character mark
  242.       getfileid fid
  243.       getmark firstline,lastline,firstcol,lastcol,fileid
  244.       if fid<>fileid then
  245.          sayerror 'Wrong file - check mark'
  246.          return
  247.       endif
  248.    else
  249.       firstline = .line; lastline = .line;
  250.       call pend_word(); lastcol = .col
  251.       call pbegin_word(); firstcol = .col
  252.    endif
  253.    .col=lastcol+1
  254.    lastline
  255.    i_s = insert_state()
  256.    if not i_s then insert_toggle; endif
  257.    keyin end_tag
  258.    firstline
  259.    .col=firstcol
  260.    keyin start_tag
  261.    if pos(leftstr(mt,1), 'BC') then  -- Block or Character mark
  262.       l = length(start_tag)
  263.       call pset_mark(firstline, lastline, firstcol+l, lastcol+(l*(lastline=firstline)), mt, fileid)
  264.    endif
  265.    if not i_s then insert_toggle; endif
  266.  
  267. defc Simple_DOC
  268.    start_line = .line
  269.    "LaTeX_IML /\documentstyle{article}/\title{}/\author{}/\date{}/\begin{document}/\maketitle/\end{document}"
  270.    start_line+2; end_line; left
  271.    if not insert_state() then insert_toggle; endif
  272.    if textline(start_line)='' then deleteline start_line; endif
  273.  
  274. defc LETTER_DOC
  275.    start_line = .line
  276. ;  "LaTeX_IML /\documentstyle{letter}/\address{}/\signature{}/\date{}/\begin{letter}{<addressee>}/\opening{Dear sirs:}//\closing{Sincerely,}/% \cc {}/% \encl/% \ps/\end{letter}"
  277.    insertline '\documentstyle{letter}', .line+1
  278.  compile if defined(my_ADDRESS)
  279.    insertline '\address{'my_ADDRESS'}', .line+2
  280.  compile else
  281.    insertline '\address{}', .line+2
  282.  compile endif
  283.  compile if defined(my_SIGNATURE)
  284.    insertline '\signature{'my_SIGNATURE'}', .line+3
  285.  compile else
  286.    insertline '\signature{}', .line+3
  287.  compile endif
  288.    start_line+3
  289.    "LaTeX_IML /\date{}/\begin{document}/\begin{letter}{<addressee>}/\opening{Dear sirs:}/%  Body of letter goes here.//\closing{Sincerely,}/% \cc {}/% \encl/% \ps/\end{letter}/\end{document}"
  290.  compile if defined(my_ADDRESS)
  291.    start_line+9; .col = 1
  292.  compile else
  293.    start_line+2; end_line; left
  294.    if not insert_state() then insert_toggle; endif
  295.  compile endif
  296.    if textline(start_line)='' then deleteline start_line; endif
  297.  
  298.