Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes
latex_parser Struct Reference

List of all members.

Public Member Functions

 latex_parser (bool unicode2)
void latex_error (string s, int i, string message)
tree parse (string s, int &i, string stop="", bool ch=false)
tree parse_backslash (string s, int &i)
tree parse_symbol (string s, int &i)
tree parse_command (string s, int &i, string which)
tree parse_argument (string s, int &i)
tree parse_unknown (string s, int &i, string which)
bool can_parse_length (string s, int i)
tree parse_length (string s, int &i)
tree parse_length_name (string s, int &i)
tree parse_verbatim (string s, int &i, string end)
tree parse (string s, bool change)

Public Attributes

int level
bool unicode

Detailed Description

Definition at line 45 of file parsetex.cpp.


Constructor & Destructor Documentation

latex_parser::latex_parser ( bool  unicode2) [inline]

Definition at line 48 of file parsetex.cpp.

: level (0), unicode (unicode2) {}

Member Function Documentation

bool latex_parser::can_parse_length ( string  s,
int  i 
)

Definition at line 711 of file parsetex.cpp.

                                               {
  if (!textm_class_flag) return false;
  int initial= i;
  int stage= 0;
  int n= N(s);
  while (i<n) {
    if (is_numeric (s[i]) || s[i] == '.' || s[i] == '-') { stage= 1; i++; }
    else if (is_space (s[i]) && stage > 0) i++;
    else if (read (s, i, "plus") || read (s, i, "\\@plus") ||
            read (s, i, "minus") || read (s, i, "\\@minus"))
      return stage >= 2;
    else if (is_tex_alpha (s[i])) {
      if (read (s, i, "cm")) stage= 2;
      else if (read (s, i, "mm")) stage= 2;
      else if (read (s, i, "pt")) stage= 2;
      else if (read (s, i, "in")) stage= 2;
      else if (read (s, i, "em")) stage= 2;
      else if (read (s, i, "pc")) stage= 2;
      else if (read (s, i, "bp")) stage= 2;
      else if (read (s, i, "dd")) stage= 2;
      else if (read (s, i, "cc")) stage= 2;
      else if (read (s, i, "sp")) stage= 2;
      else return false;
      if (i<n && is_tex_alpha (s[i])) return false;
    }
    else if (s[i] == '\\') {
      i++;
      int start= i;
      while (i<n && is_tex_alpha (s[i])) i++;
      if (latex_type (s (start, i)) != "length") return false;
      return s[initial] != '\\' || level > 1;
    }
    else return false;
  }
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void latex_parser::latex_error ( string  s,
int  i,
string  message 
)

Definition at line 70 of file parsetex.cpp.

                                                          {
  if (!textm_class_flag) {
    cerr << "Latex error] " << message << "\n";
    if (i>30) s= "..." * s (i-27, N(s));
    if (N(s)>60) s= s (0, 57) * "...";
    cerr << "Latex error] in " << s << "\n";
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree latex_parser::parse ( string  s,
int &  i,
string  stop = "",
bool  ch = false 
)

Definition at line 104 of file parsetex.cpp.

                                                               {
  bool no_error= true;
  int n= N(s);
  tree t (CONCAT);

  level++;
  command_type ->extend ();
  command_arity->extend ();
  command_def  ->extend ();

  while ((i<n) && is_space (s[i])) i++;
  while ((i<n) && no_error &&
        (s[i] != '\0' || N (stop) != 0) &&
        (N(stop) != 1 || s[i] != stop[0]) &&
        (s[i] != '$' || stop != "$$" || i+1>=n || s[i+1] != '$') &&
        (stop != "denom" ||
         (s[i] != '$' && s[i] != '}' &&
          (i+2>n || s(i,i+2) != "\\]") &&
          (i+4>n || s(i,i+4) != "\\end")))) {
    switch (s[i]) {
    case '~':
      t << tuple ("\\nbsp");
      i++;
      break;
    case ' ':
    case '\t':
    case '\r':
      while ((i<n) && ((s[i]==' ') || (s[i]=='\t') || (s[i]=='\r'))) i++;
      if ((i<n) && (s[i]!='\n')) t << " ";
      break;
    case '\n': {
      int ln=0;
      while ((i<n) && is_space (s[i]))
       if (s[i++]=='\n') ln++;
      if (i<n) {
       if (ln == 1) t << " ";
       else t << "\n";
      }
      break;
    }
    case '%': {
      while ((i<n) && (s[i]!='\n')) i++;
      if (i<n) i++;
      int ln=0;
      while ((i<n) && is_space (s[i]))
       if (s[i++]=='\n') ln++;
      if (ln > 0) {
       if ((N(t)>0) && ((t[N(t)-1]==" ") || (t[N(t)-1]=="\n")))
         t[N(t)-1]= "\n";
       else t << "\n";
      }
      break;
    }
    case '#':
      i++;
      if (i==n) return t;
      if (is_numeric (s[i])) {
       t << s (i-1, i+1);
       i++;
      }
      else t << s (i-1, i);
      break;
    case '\\':
      if (((i+7)<n) && !is_tex_alpha (s (i+5, i+7)) &&
         (s (i, i+5) == "\\over" || s (i, i+5) == "\\atop"))
       {
         string fr_cmd= s(i,i+5);
         if (fr_cmd == "\\over") fr_cmd= "\\frac";
         if (fr_cmd == "\\atop") fr_cmd= "\\ontop";
         int j;
         for (j=N(t); j>0 && is_regular (t[j-1]); j--) {}
         tree num= t (j, N(t));
         if (N(num) == 0) num= "";
         t= t (0, j);
         i+=5;
         while (i<n && (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')) i++;
         tree den= parse (s, i, "denom");
         t << tree (TUPLE, fr_cmd, num, den);
       }
      else if ((i+5) < n && s(i,i+3) == "\\sp" && !is_tex_alpha (s[i+3])) {
       i+=3;
       t << parse_command (s, i, "\\<sup>");
      }
      else if ((i+5) < n && s(i,i+3) == "\\sb" && !is_tex_alpha (s[i+3])) {
       i+=3;
       t << parse_command (s, i, "\\<sub>");
      }
      else if ((i+10) < n && s(i,i+8) == "\\pmatrix") {
       i+=8;
       tree arg= parse_command (s, i, "\\pmatrix");
       if (is_tuple (arg, "\\pmatrix", 1)) arg= arg[1];
       t << tree (TUPLE, "\\begin-pmatrix");
       if (is_concat (arg)) t << A (arg);
       else t << arg;
       t << tree (TUPLE, "\\end-pmatrix");
      }
      else if (can_parse_length (s, i))
       t << parse_length (s, i);
      else {
       tree u= parse_backslash (s, i);
       if (u != "") t << u;
      }
      break;
    case '\'':
      i++;
      if (command_type ["!mode"] == "math") {
       int start= i-1;
       while ((i < N(s)) && (s[i] == '\'')) i++;
       t << tuple ("\\prime", s (start, i));
      }
      else t << s (i-1, i);
      break;
    case '*':
      if (command_type ["!mode"] == "math") t << tree (TUPLE, "\\ast");
      else t << "*";
      i++;
      break;
    case '_':
      i++;
      t << parse_command (s, i, "\\<sub>");
      /*
      if (command_type ["!mode"] == "math")
       t << parse_command (s, i, "\<sub>");
      else t << s (i-1, i);
      */
      break;
    case '^':
      i++;
      t << parse_command (s, i, "\\<sup>");
      /*
      if (command_type ["!mode"] == "math")
       t << parse_command (s, i, "\<sup>");
      else t << s (i-1, i);
      */
      break;
    case '<':
      t << tree (TUPLE, "\\<less>");
      i++;
      break;
    case '>':
      t << tree (TUPLE, "\\<gtr>");
      i++;
      break;
    case '\244':
      i++;
      t << parse_verbatim (s, i, "\244");
      break;
    case '{': {
      i++;
      t << parse (s, i, "}");
      if ((i<n) && (s[i]=='}')) i++;

      int ln=0;
      if ((i<n) && (!is_space (s[i]))) break;
      while ((i<n) && is_space (s[i]))
       if (s[i++]=='\n') ln++;
      if (ln >= 2) t << "\n";
      else if (i<n) t << tree (TUPLE, "\\ ");
      break;
    }
    case '$': {
      i++;
      if ((i<n) & (s[i]=='$')) {
       i++;
       t << tree (TUPLE, "\\begin-displaymath");
       command_type ("!mode")= "math";
       t << parse (s, i, "$$");
       command_type ("!mode")= "text";
       if ((i<n) && (s[i]=='$')) i++;
       if ((i<n) && (s[i]=='$')) i++;
       t << tree (TUPLE, "\\end-displaymath");
      }
      else {
       t << tree (TUPLE, "\\begin-math");
       command_type ("!mode")= "math";
       t << parse (s, i, "$");
       command_type ("!mode")= "text";
       if ((i<n) && (s[i]=='$')) i++;
       t << tree (TUPLE, "\\end-math");
      }
      break;
    }
    default:
      if ((s[i] == '-' || (s[i] >= '0' && s[i] <= '9')) &&
         can_parse_length (s, i))
       t << parse_length (s, i);
      else if (unicode && ((unsigned char) s[i]) >= 128) {
       unsigned int code= decode_from_utf8 (s, i);
       t << tree (TUPLE, "\\#" * as_hexadecimal (code));
      }
      else if (!unicode && is_iso_alpha (s[i])) {
       // If we encounter too much text in math mode, then return
       int start= i;
       while ((i<n) && is_iso_alpha (s[i])) i++;
       int end= i;
       if ((i >= start+3) && (command_type ["!mode"] == "math")) {
         while ((i<n) && (is_iso_alpha (s[i]) ||
                        is_punctuation (s[i]) ||
                        is_space (s[i])))
           i++;
         if (i >= start+20) {
           int last= i, words= 0, letters= 0;
           for (i=start; i<last; i++) {
             if (is_iso_alpha (s[i])) {
              letters++;
              if ((i==start) || (!is_iso_alpha (s[i-1]))) words++;
             }
           }
           if ((words > 3) && (letters/words >= 3) && (letters >= 15)) {
             i= start;
             no_error= false;
           }
         }
       }
       if (no_error)
         for (i=start; i<end; i++)
           t << s(i, i+1);
      }
      else {
       t << s (i, i+1);
       i++;
      }
      break;
    }
  }

  level--;
  if (change) {
    command_type ->merge ();
    command_arity->merge ();
    command_def  ->merge ();
  }
  else {
    command_type ->shorten ();
    command_arity->shorten ();
    command_def  ->shorten ();
  }

  if (N(t)==0) return "";
  if (N(t)==1) return t[0];
  return t;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree latex_parser::parse ( string  s,
bool  change 
)

Definition at line 921 of file parsetex.cpp.

                                          {
  command_type ->extend ();
  command_arity->extend ();
  command_def  ->extend ();

  // We first cut the string into pieces at strategic places
  // This reduces the risk that the parser gets confused
  array<string> a;
  int i, start=0, n= N(s);
  for (i=0; i<n; i++)
    if (s[i]=='\n' || (s[i] == '\\' && test (s, i, "\\nextbib"))) {
      while ((i<n) && is_space (s[i])) i++;
      if (test (s, i, "%%%%%%%%%% Start TeXmacs macros\n")) {
       a << s (start, i);
       while ((i<n) && (!test (s, i, "%%%%%%%%%% End TeXmacs macros\n")))
         i++;
       i += 30;
       start= i;
       continue;
      }
      if (test (s, i, "\\begin{document}") ||
         test (s, i, "\\begin{abstract}") ||
         test (s, i, "\\chapter") ||
         test (s, i, "\\section") ||
         test (s, i, "\\subsection") ||
         test (s, i, "\\subsubsection") ||
         test (s, i, "\\paragraph") ||
         test (s, i, "\\subparagraph") ||
         test (s, i, "\\nextbib") ||
         test (s, i, "\\newcommand") ||
         test (s, i, "\\def") ||
         test (s, i, "\\input{") ||
         test (s, i, "\\include{"))
       {
         a << s (start, i);
         start= i;
          if (test (s, i, "\\input{") || test (s, i, "\\include{")) {
           while (i<N(s) && s[i] != '{') i++;
           int start_name= i+1;
            while (i<N(s) && s[i] != '}') i++;
            string name= s (start_name, i);
            if (!ends (name, ".tex")) name= name * ".tex";
            url incl= relative (get_file_focus (), name);
            string body;
            if (!exists (incl) || load_string (incl, body, false)) i++;
            else {
              //cout << "Include " << name << " -> " << incl << "\n";
              s= s (0, start) * "\n" * body * "\n" * s (i+1, N(s));
              n= N(s);
              i= start + 1;
            }
            start= i;
          }
          while (i < n && test (s, i, "\\nextbib{}")) {
            i += 10;
            a << s (start, i);
            start= i;
          }
       }
      if (i == n) break;
    }
  a << s (start, i);

  // We now parse each of the pieces
  tree t (CONCAT);
  for (i=0; i<N(a); i++) {
    int j=0;
    while (j<N(a[i])) {
      int start= j;
      command_type ("!mode") = "text";
      command_type ("!em") = "false";
      tree u= parse (a[i], j, "", true);
      if ((N(t)>0) && (t[N(t)-1]!='\n') && (start==0)) t << "\n";
      if (is_concat (u)) t << A(u);
      else t << u;
      if (j == start) j++;
    }
  }

  if (change) {
    command_type ->merge ();
    command_arity->merge ();
    command_def  ->merge ();
  }
  else {
    command_type ->shorten ();
    command_arity->shorten ();
    command_def  ->shorten ();
  }
  //cout << "Parsed " << t << "\n";
  return t;
}

Here is the call graph for this function:

Definition at line 668 of file parsetex.cpp.

                                              {
  skip_spaces (s, i);
  if (s[i] == '{') {
    i++;
    return parse (s, i, "}");
  }
  else parse_symbol (s, i);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 352 of file parsetex.cpp.

                                               {
  int n= N(s);
  if (((i+7)<n) && (s(i,i+5)=="\\verb")) {
    i+=6;
    return parse_verbatim (s, i, s(i-1,i));
  }
  if (((i+29)<n) && (s(i,i+16)=="\\begin{verbatim}")) {
    i+=16;
    return parse_verbatim (s, i, "\\end{verbatim}");
  }
  if (((i+5)<n) && (s(i,i+4)=="\\url") && !is_tex_alpha (s[i+5])) {
    i+=4;
    while (i<n && (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')) i++;
    string ss;
    if (i<n && s[i] == '{') {
      i++;
      int start= i;
      while ((i<n) && s[i] != '}') i++;
      ss= s (start, i++);
    }
    return tree (TUPLE, "\\url", ss);
  }
  if (((i+6)<n) && (s(i,i+5)=="\\href")) {
    i+=5;
    while (i<n && (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')) i++;
    string ss;
    if (i<n && s[i] == '{') {
      i++;
      int start= i;
      while ((i<n) && s[i] != '}') i++;
      ss= s (start, i++);
    }
    tree u= "";
    while (i<n && (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')) i++;
    if (i<n && s[i] == '{') { i++; u= parse (s, i, "}"); i++; }
    return tree (TUPLE, "\\href", ss, u);
  }

  /************************ special commands *********************************/
  i++;
  if (i==n) return "";
  if (s[i]==' ') {
    i++;
    return tree (TUPLE, "\\ ");
  }
  if (!is_tex_alpha(s[i])) {
    i++;
    if (s[i-1]=='(') return parse_command (s, i, "\\begin-math");
    if (s[i-1]==')') return parse_command (s, i, "\\end-math");
    if (s[i-1]=='[') return parse_command (s, i, "\\begin-displaymath");
    if (s[i-1]==']') return parse_command (s, i, "\\end-displaymath");
    return parse_command (s, i, s (i-2, i));
  }

  /************************* normal commands *********************************/
  int start= i-1;
  while ((i<n) && is_tex_alpha (s[i])) i++;
  if ((i<n) && (s[i]=='*') && latex_type (s (start, i+1)) != "undefined") i++;
  string r= s (start, i);
  if ((r == "\\begin") || (r == "\\end")) {
    while ((i<n) && is_space (s[i])) i++;
    if ((i==n) || (s[i]!='{')) {
      latex_error (s, i, "begin or end which environment ?");
      return "";
    }
    i++; start= i;
    while ((i<n) && (s[i]!='}')) i++;
    r = r * "-" * s (start, i);
    if (i<n) i++;
  }
  return parse_command (s, i, r);
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree latex_parser::parse_command ( string  s,
int &  i,
string  which 
)

Definition at line 491 of file parsetex.cpp.

                                                         {
  //cout << cmd << " [" << latex_type (cmd) << ", "
  //<< command_type ["!mode"] << ", " << latex_arity (cmd) << "]" << LF;
  if (cmd == "\\newcommand") cmd= "\\def";
  if (cmd == "\\renewcommand") cmd= "\\def";
  if (cmd == "\\renewenvironment") cmd= "\\newenvironment";
  if (cmd == "\\begin-split") cmd= "\\begin-eqsplit";
  if (cmd == "\\end-split") cmd= "\\end-eqsplit";
  if (cmd == "\\begin-split*") cmd= "\\begin-eqsplit*";
  if (cmd == "\\end-split*") cmd= "\\end-eqsplit*";

  if (latex_type (cmd) == "undefined")
    return parse_unknown (s, i, cmd);

  if (latex_type (cmd) == "math-environment") {
    if (cmd (0, 6) == "\\begin") command_type ("!mode") = "math";
    else command_type ("!mode") = "text";
  }

  if (textm_class_flag && level <= 1 && latex_type (cmd) == "length") {
    //cout << "Parse length " << cmd << "\n";
    int n= N(s);
    while (i<n && (is_space (s[i]) || s[i] == '=')) i++;
    tree len= parse_length (s, i);
    //cout << "Got " << len << "\n";
    return tree (TUPLE, "\\setlength", copy (cmd), copy (len));
  }

  if (cmd == "\\setlength") {
    tree name= parse_length_name (s, i);
    tree arg = parse_argument (s, i);
    return tuple (cmd, name, arg);
  }

  bool mbox_flag=
    ((cmd == "\\text") || (cmd == "\\mbox")) &&
    (command_type ["!mode"] == "math");
  if (mbox_flag) command_type ("!mode") = "text";

  int  n     = N(s);
  int  arity = latex_arity (cmd);
  bool option= (arity<0);
  if (option) arity= -1-arity;

  /************************ retrieve arguments *******************************/
  tree t (TUPLE, copy (cmd)); // parsed arguments
  tree u (TUPLE, copy (cmd)); // unparsed arguments
  while (i<n && arity>=0 && (arity>0 || option)) {
    int j= i;
    while ((j<n) && is_space (s[j])) j++;
    if (j==n) break;
    if (option && (s[j]=='[')) {
      j++;
      i=j;
      tree opt= parse (s, i, "]");
      if (cmd != "\\newtheorem" && cmd != "\\newtheorem*")
       t << opt;
      u << s (j, i);
      if ((i<n) && (s[i]==']')) i++;
      if (cmd != "\\newtheorem" && cmd != "\\newtheorem*")
       t[0]->label= t[0]->label * "*";
      option= false;
    }
    else if ((arity>0) && (s[j]=='{')) {
      bool text_arg=
       (command_type["!mode"] == "math") && is_text_argument (cmd, arity);
      j++;
      i=j;
      if (text_arg) command_type ("!mode")= "text";
      if ((N(t)==1) && (cmd == "\\def")) {
       while ((i<n) && (s[i]!='}')) i++;
       t << s (j, i);
      }
      else t << parse (s, i, "}");
      if (text_arg) command_type ("!mode")= "math";
      u << s (j, i);
      if ((i<n) && (s[i]=='}')) i++;
      arity--;
      if (arity == 0) option= false;
    }
    else if (s[j] == '}') break;
    else if (option && (s[j]=='#') && (cmd == "\\def")) {
      while ((j+3 <= n) && is_numeric (s[j+1]) && (s[j+2] == '#')) j+=2;
      if (j+2<=n) {
       t << s (j+1, j+2);
       u << s (j+1, j+2);
       i= j+2;
      }
      t[0]->label= t[0]->label * "*";
      option= false;
    }
    else {
      if (arity>0) {
       i=j;
       tree st= parse_symbol (s, i);
       t << st;
       u << st;
       arity--;
       if (arity == 0) option= false;
      }
      else break;
    }
  }
  if (arity>0) latex_error (s, i, "too little arguments for " * cmd);

  /******************** new commands and environments ************************/
  if (is_tuple (t, "\\def", 2)) {
    string var= string_arg (t[1]);
    command_type  (var)= "user";
    command_arity (var)= 0;
    command_def   (var)= as_string (u[2]);
  }
  if (is_tuple (t, "\\def*", 3)) {
    string var= string_arg (t[1]);
    command_type  (var)= "user";
    command_arity (var)= as_int (t[2]);
    command_def   (var)= as_string (u[3]);
  }
  if (is_tuple (t, "\\newtheorem", 2) || is_tuple (t, "\\newtheorem*", 2)) {
    string var= "\\begin-" * string_arg (t[1]);
    command_type  (var)= "environment";
    command_arity (var)= 0;
    var= "\\end-" * string_arg (t[1]);
    command_type  (var)= "environment";
    command_arity (var)= 0;
  }
  if (is_tuple (t, "\\newdimen", 1) || is_tuple (t, "\\newlength", 1)) {
    string var= string_arg (t[1]);
    command_type  (var)= "length";
    command_arity (var)= 0;
  }
  if (is_tuple (t, "\\newenvironment", 3)) {
    string var= "\\begin-" * string_arg (t[1]);
    command_type  (var)= "user";
    command_arity (var)= 0;
    command_def   (var)= as_string (u[2]);
    if (is_math_environment (t)) command_type (var)= "math-environment";
    var= "\\end-" * string_arg (t[1]);
    command_type  (var)= "user";
    command_arity (var)= 0;
    command_def   (var)= as_string (u[3]);
    if (is_math_environment (t)) command_type (var)= "math-environment";
  }
  if (is_tuple (t, "\\newenvironment*", 4)) {
    string var= "\\begin-" * string_arg (t[1]);
    command_type  (var)= "user";
    command_arity (var)= as_int (t[2]);
    command_def   (var)= as_string (u[3]);
    if (is_math_environment (t)) command_type (var)= "math-environment";
    var= "\\end-" * string_arg (t[1]);
    command_type  (var)= "user";
    command_arity (var)= 0;
    command_def   (var)= as_string (u[4]);
    if (is_math_environment (t)) command_type (var)= "math-environment";
  }

  /***************** environment changes for user commands  ******************/
  if (latex_type (cmd) == "user") {
    int pos= 0;
    string body= command_def[cmd];
    textm_recursion_level (cmd)++;
    if (textm_recursion_level [cmd] <= 5) {
      if (count_occurrences ("\\begin", body) ==
         count_occurrences ("\\end", body))
       (void) parse (sharp_to_arg (body, u), pos, "", true);
      else t= parse (sharp_to_arg (body, u), pos, "", true);
    }
    textm_recursion_level (cmd)--;
    // replaces macros by their definitions in the case when
    // the user defined shorthands for \\begin{env} and \\end{env}
  }

  if (mbox_flag) command_type ("!mode") = "math";
  return t;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree latex_parser::parse_length ( string  s,
int &  i 
)

Definition at line 749 of file parsetex.cpp.

                                            {
  int n= N(s);
  tree r= tree (CONCAT);
  while (i<n) {
    if (is_numeric (s[i]) || s[i] == '.' || s[i] == '-')
      r << s (i, i+1);
    else if (read (s, i, "plus") || read (s, i, "\\@plus")) {
      tree next= parse_length (s, i);
      if (is_tuple (next, "\\tex-len", 3)) {
       //ASSERT (next[2] == "0pt", "invalid multiple plus");
       return tuple ("\\tex-len", r, next[1], next[3]);
      }
      else return tuple ("\\tex-len", r, next, "0pt");
    }
    else if (read (s, i, "minus") || read (s, i, "\\@minus")) {
      tree next= parse_length (s, i);
      if (is_tuple (next, "\\tex-len", 3)) {
       //ASSERT (next[3] == "0pt", "invalid multiple minus");
       return tuple ("\\tex-len", r, next[2], next[1]);
      }
      else return tuple ("\\tex-len", r, "0pt", next);
    }
    else if (is_tex_alpha (s[i]) && N(r) > 0 && is_atomic (r[N(r)-1]) &&
            (is_numeric (r[N(r)-1]->label) ||
             r[N(r)-1] == "." || r[N(r)-1] == "-")) {
      for (;i<n && is_tex_alpha (s[i]); i++)
       r << s (i, i+1);
      continue;
    }
    else if (s[i] == '\\') {
      i++;
      int start= i;
      while (i<n && is_tex_alpha (s[i])) i++;
      string unit= s (start, i);
      if (latex_type (unit) != "length") { i= start-1; break; }
      // FIXME
      if (unit == "p@")
       r << string ("p") << string ("t");
      else if (unit == "z@")
       r << string ("0") << string ("p") << string ("t");
      // FIXME
      continue;
    }
    else if (is_space (s[i]));
    else break;
    i++;
  }
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 800 of file parsetex.cpp.

                                                 {
  skip_spaces (s, i);
  if (s[i] == '{') {
    i++;
    tree r= parse_length_name (s, i);
    skip_spaces (s, i);
    if (s[i] == '}') i++;
    return r;
  }
  else if (s[i] == '\\') {
    int start= i;
    i++;
    while (i<N(s) && is_tex_alpha (s[i])) i++;
    return s (start, i);
  }
  else return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree latex_parser::parse_symbol ( string  s,
int &  i 
)

Definition at line 439 of file parsetex.cpp.

                                            {
  int start= i;
  if ((s[i] == '*') && (command_type ["!mode"] == "math")) {
    i++; return tree (TUPLE, "\\ast"); }
  if (s[i] == '<') { i++; return tree (TUPLE, "\\<less>"); }
  if (s[i] == '>') { i++; return tree (TUPLE, "\\<gtr>"); }
  if (s[i] != '\\') { i++; return s(start, i); }
  i++;
  if (i == N(s)) return tree (TUPLE, "\\backslash");
  if (!is_tex_alpha (s[i])) { i++; return s(start, i); }
  while ((i<N(s)) && is_tex_alpha (s[i])) i++;
  if ((i<N(s)) && (s[i]=='*')) i++;
  return s(start,i);
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree latex_parser::parse_unknown ( string  s,
int &  i,
string  which 
)

Definition at line 678 of file parsetex.cpp.

                                                         {
  int  n     = N(s);
  bool option= false;

  tree t (TUPLE, copy (cmd));
  while (i<n) {
    int j=i;
    while ((j<n) && is_space (s[j])) j++;
    if (j==n) break;
    if (option && (s[j]=='[')) {
      j++;
      i=j;
      t << parse (s, i, "]");
      if ((i<n) && (s[i]==']')) i++;
      t[0]->label= t[0]->label * "*";
      option= false;
    }
    else if (s[j]=='{') {
      j++;
      i=j;
      t << parse (s, i, "}");
      if ((i<n) && (s[i]=='}')) i++;
    }
    else break;
  }
  return t;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree latex_parser::parse_verbatim ( string  s,
int &  i,
string  end 
)

Definition at line 823 of file parsetex.cpp.

                                                          {
  int start=i, n= N(s), e= N(end);
  while ((i<(n-e)) && (s(i,i+e)!=end)) i++;
  i+=e;
  return tree (CONCAT,
              tree (TUPLE, "\\begin-verbatim"),
              s(start,i-e),
              tree (TUPLE, "\\end-verbatim"));
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 46 of file parsetex.cpp.

Definition at line 47 of file parsetex.cpp.


The documentation for this struct was generated from the following file: