| author | wenzelm | 
| Tue, 21 Sep 2021 11:34:58 +0200 | |
| changeset 74337 | 9c1ad2f04660 | 
| parent 73783 | e4d50a660140 | 
| child 74748 | 95643a0bff49 | 
| permissions | -rw-r--r-- | 
| 67172 | 1  | 
/* Title: Pure/Thy/latex.scala  | 
2  | 
Author: Makarius  | 
|
3  | 
||
4  | 
Support for LaTeX.  | 
|
5  | 
*/  | 
|
6  | 
||
7  | 
package isabelle  | 
|
8  | 
||
9  | 
||
| 67173 | 10  | 
import java.io.{File => JFile}
 | 
11  | 
||
| 67172 | 12  | 
import scala.annotation.tailrec  | 
| 71601 | 13  | 
import scala.util.matching.Regex  | 
| 67172 | 14  | 
|
15  | 
||
16  | 
object Latex  | 
|
17  | 
{
 | 
|
| 
73780
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
18  | 
/* output text and positions */  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
19  | 
|
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
20  | 
type Text = XML.Body  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
21  | 
|
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
22  | 
def output(latex_text: Text, file_pos: String = ""): String =  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
23  | 
  {
 | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
24  | 
def position(a: String, b: String): String = "%:%" + a + "=" + b + "%:%"  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
25  | 
|
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
26  | 
var positions: List[String] =  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
27  | 
if (file_pos.isEmpty) Nil  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
28  | 
else List(position(Markup.FILE, file_pos), "\\endinput")  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
29  | 
|
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
30  | 
var line = 1  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
31  | 
var result = List.empty[String]  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
32  | 
|
| 73783 | 33  | 
def traverse(body: XML.Body): Unit =  | 
| 
73780
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
34  | 
    {
 | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
35  | 
      body.foreach {
 | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
36  | 
case XML.Wrapped_Elem(_, _, _) =>  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
37  | 
case XML.Elem(markup, body) =>  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
38  | 
          if (markup.name == Markup.DOCUMENT_LATEX) {
 | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
39  | 
            for { l <- Position.Line.unapply(markup.properties) if positions.nonEmpty } {
 | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
40  | 
val s = position(Value.Int(line), Value.Int(l))  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
41  | 
if (positions.head != s) positions ::= s  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
42  | 
}  | 
| 73783 | 43  | 
traverse(body)  | 
| 
73780
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
44  | 
}  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
45  | 
case XML.Text(s) =>  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
46  | 
line += s.count(_ == '\n')  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
47  | 
result ::= s  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
48  | 
}  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
49  | 
}  | 
| 73783 | 50  | 
traverse(latex_text)  | 
| 
73780
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
51  | 
|
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
52  | 
result.reverse.mkString + cat_lines(positions.reverse)  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
53  | 
}  | 
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
54  | 
|
| 
 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 
wenzelm 
parents: 
73736 
diff
changeset
 | 
55  | 
|
| 67173 | 56  | 
/* generated .tex file */  | 
57  | 
||
| 67184 | 58  | 
private val File_Pattern = """^%:%file=(.+)%:%$""".r  | 
| 
67194
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
59  | 
private val Line_Pattern = """^*%:%(\d+)=(\d+)%:%$""".r  | 
| 67173 | 60  | 
|
61  | 
def read_tex_file(tex_file: Path): Tex_File =  | 
|
| 
67194
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
62  | 
  {
 | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
63  | 
val positions =  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
64  | 
Line.logical_lines(File.read(tex_file)).reverse.  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
65  | 
takeWhile(_ != "\\endinput").reverse  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
66  | 
|
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
67  | 
val source_file =  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
68  | 
      positions match {
 | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
69  | 
case File_Pattern(file) :: _ => Some(file)  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
70  | 
case _ => None  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
71  | 
}  | 
| 67173 | 72  | 
|
| 
67194
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
73  | 
val source_lines =  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
74  | 
if (source_file.isEmpty) Nil  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
75  | 
else  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
76  | 
positions.flatMap(line =>  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
77  | 
          line match {
 | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
78  | 
case Line_Pattern(Value.Int(line), Value.Int(source_line)) => Some(line -> source_line)  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
79  | 
case _ => None  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
80  | 
})  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
81  | 
|
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
82  | 
new Tex_File(tex_file, source_file, source_lines)  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
83  | 
}  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
84  | 
|
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
85  | 
final class Tex_File private[Latex](  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
86  | 
tex_file: Path, source_file: Option[String], source_lines: List[(Int, Int)])  | 
| 67173 | 87  | 
  {
 | 
88  | 
override def toString: String = tex_file.toString  | 
|
89  | 
||
| 
67194
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
90  | 
def source_position(l: Int): Option[Position.T] =  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
91  | 
      source_file match {
 | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
92  | 
case None => None  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
93  | 
case Some(file) =>  | 
| 
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
94  | 
val source_line =  | 
| 73359 | 95  | 
            source_lines.iterator.takeWhile({ case (m, _) => m <= l }).
 | 
96  | 
              foldLeft(0) { case (_, (_, n)) => n }
 | 
|
| 
67194
 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 
wenzelm 
parents: 
67190 
diff
changeset
 | 
97  | 
if (source_line == 0) None else Some(Position.Line_File(source_line, file))  | 
| 67173 | 98  | 
}  | 
99  | 
||
100  | 
def position(line: Int): Position.T =  | 
|
| 
67188
 
bc7a6455e12a
simplified positions -- line is also human-readable in generated .tex file;
 
wenzelm 
parents: 
67184 
diff
changeset
 | 
101  | 
source_position(line) getOrElse Position.Line_File(line, tex_file.implode)  | 
| 67173 | 102  | 
}  | 
103  | 
||
104  | 
||
105  | 
/* latex log */  | 
|
106  | 
||
| 73782 | 107  | 
def latex_errors(dir: Path, root_name: String): List[String] =  | 
108  | 
  {
 | 
|
109  | 
    val root_log_path = dir + Path.explode(root_name).ext("log")
 | 
|
110  | 
    if (root_log_path.is_file) {
 | 
|
111  | 
      for { (msg, pos) <- filter_errors(dir, File.read(root_log_path)) }
 | 
|
112  | 
yield "Latex error" + Position.here(pos) + ":\n" + Library.indent_lines(2, msg)  | 
|
113  | 
}  | 
|
114  | 
else Nil  | 
|
115  | 
}  | 
|
116  | 
||
| 67173 | 117  | 
def filter_errors(dir: Path, root_log: String): List[(String, Position.T)] =  | 
| 67172 | 118  | 
  {
 | 
| 67173 | 119  | 
val seen_files = Synchronized(Map.empty[JFile, Tex_File])  | 
120  | 
||
121  | 
def check_tex_file(path: Path): Option[Tex_File] =  | 
|
122  | 
seen_files.change_result(seen =>  | 
|
123  | 
        seen.get(path.file) match {
 | 
|
124  | 
case None =>  | 
|
125  | 
            if (path.is_file) {
 | 
|
126  | 
val tex_file = read_tex_file(path)  | 
|
127  | 
(Some(tex_file), seen + (path.file -> tex_file))  | 
|
128  | 
}  | 
|
129  | 
else (None, seen)  | 
|
130  | 
case some => (some, seen)  | 
|
131  | 
})  | 
|
132  | 
||
133  | 
def tex_file_position(path: Path, line: Int): Position.T =  | 
|
134  | 
      check_tex_file(path) match {
 | 
|
135  | 
case Some(tex_file) => tex_file.position(line)  | 
|
136  | 
case None => Position.Line_File(line, path.implode)  | 
|
137  | 
}  | 
|
138  | 
||
| 67172 | 139  | 
object File_Line_Error  | 
140  | 
    {
 | 
|
| 71601 | 141  | 
val Pattern: Regex = """^(.*?\.\w\w\w):(\d+): (.*)$""".r  | 
| 67173 | 142  | 
def unapply(line: String): Option[(Path, Int, String)] =  | 
| 67172 | 143  | 
        line match {
 | 
144  | 
case Pattern(file, Value.Int(line), message) =>  | 
|
145  | 
val path = File.standard_path(file)  | 
|
146  | 
            if (Path.is_wellformed(path)) {
 | 
|
| 67183 | 147  | 
val file = (dir + Path.explode(path)).canonical  | 
| 67423 | 148  | 
              val msg = Library.perhaps_unprefix("LaTeX Error: ", message)
 | 
149  | 
if (file.is_file) Some((file, line, msg)) else None  | 
|
| 67172 | 150  | 
}  | 
151  | 
else None  | 
|
152  | 
case _ => None  | 
|
153  | 
}  | 
|
154  | 
}  | 
|
155  | 
||
| 
67418
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
156  | 
val Line_Error = """^l\.\d+ (.*)$""".r  | 
| 
67196
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
157  | 
val More_Error =  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
158  | 
List(  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
159  | 
"<argument>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
160  | 
"<template>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
161  | 
"<recently read>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
162  | 
"<to be read again>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
163  | 
"<inserted text>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
164  | 
"<output>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
165  | 
"<everypar>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
166  | 
"<everymath>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
167  | 
"<everydisplay>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
168  | 
"<everyhbox>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
169  | 
"<everyvbox>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
170  | 
"<everyjob>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
171  | 
"<everycr>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
172  | 
"<mark>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
173  | 
"<everyeof>",  | 
| 
 
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
 
wenzelm 
parents: 
67194 
diff
changeset
 | 
174  | 
        "<write>").mkString("^(?:", "|", ") (.*)$").r
 | 
| 67172 | 175  | 
|
| 
73474
 
4e12a6caefb3
turn LaTeX warning into error, for the sake of isabelle.sty/bbbfont;
 
wenzelm 
parents: 
73359 
diff
changeset
 | 
176  | 
val Bad_Font = """^LaTeX Font Warning: (Font .*\btxmia\b.* undefined).*$""".r  | 
| 
67483
 
aae933ca6fbd
tuned message: same error may occur in different contexts;
 
wenzelm 
parents: 
67482 
diff
changeset
 | 
177  | 
val Bad_File = """^! LaTeX Error: (File `.*' not found\.)$""".r  | 
| 67482 | 178  | 
|
| 67423 | 179  | 
val error_ignore =  | 
180  | 
Set(  | 
|
181  | 
"See the LaTeX manual or LaTeX Companion for explanation.",  | 
|
182  | 
"Type H <return> for immediate help.")  | 
|
183  | 
||
| 
67418
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
184  | 
def error_suffix1(lines: List[String]): Option[String] =  | 
| 
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
185  | 
    {
 | 
| 71784 | 186  | 
val lines1 =  | 
187  | 
        lines.take(20).takeWhile({ case File_Line_Error((_, _, _)) => false case _ => true })
 | 
|
| 
67418
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
188  | 
      lines1.zipWithIndex.collectFirst({
 | 
| 67423 | 189  | 
case (Line_Error(msg), i) =>  | 
190  | 
cat_lines(lines1.take(i).filterNot(error_ignore) ::: List(msg)) })  | 
|
| 
67418
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
191  | 
}  | 
| 
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
192  | 
def error_suffix2(lines: List[String]): Option[String] =  | 
| 
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
193  | 
      lines match {
 | 
| 
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
194  | 
case More_Error(msg) :: _ => Some(msg)  | 
| 
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
195  | 
case _ => None  | 
| 
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
196  | 
}  | 
| 
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
197  | 
|
| 67173 | 198  | 
@tailrec def filter(lines: List[String], result: List[(String, Position.T)])  | 
199  | 
: List[(String, Position.T)] =  | 
|
200  | 
    {
 | 
|
| 67172 | 201  | 
      lines match {
 | 
| 67173 | 202  | 
case File_Line_Error((file, line, msg1)) :: rest1 =>  | 
| 67183 | 203  | 
val pos = tex_file_position(file, line)  | 
| 
67418
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
204  | 
val msg2 = error_suffix1(rest1) orElse error_suffix2(rest1) getOrElse ""  | 
| 
 
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
 
wenzelm 
parents: 
67417 
diff
changeset
 | 
205  | 
filter(rest1, (Exn.cat_message(msg1, msg2), pos) :: result)  | 
| 
73474
 
4e12a6caefb3
turn LaTeX warning into error, for the sake of isabelle.sty/bbbfont;
 
wenzelm 
parents: 
73359 
diff
changeset
 | 
206  | 
case Bad_Font(msg) :: rest =>  | 
| 
 
4e12a6caefb3
turn LaTeX warning into error, for the sake of isabelle.sty/bbbfont;
 
wenzelm 
parents: 
73359 
diff
changeset
 | 
207  | 
filter(rest, (msg, Position.none) :: result)  | 
| 
67483
 
aae933ca6fbd
tuned message: same error may occur in different contexts;
 
wenzelm 
parents: 
67482 
diff
changeset
 | 
208  | 
case Bad_File(msg) :: rest =>  | 
| 67482 | 209  | 
filter(rest, (msg, Position.none) :: result)  | 
| 67172 | 210  | 
case _ :: rest => filter(rest, result)  | 
211  | 
case Nil => result.reverse  | 
|
212  | 
}  | 
|
| 67173 | 213  | 
}  | 
| 67172 | 214  | 
|
| 67174 | 215  | 
filter(Line.logical_lines(root_log), Nil)  | 
| 67173 | 216  | 
}  | 
| 67172 | 217  | 
}  |