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