author | wenzelm |
Sat, 20 Nov 2021 18:15:09 +0100 | |
changeset 74823 | d6ce4ce20422 |
parent 74790 | 3ce6fb9db485 |
child 74824 | 6424f74fd9d4 |
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 |
74748 | 13 |
import scala.collection.mutable |
71601 | 14 |
import scala.util.matching.Regex |
67172 | 15 |
|
16 |
||
17 |
object Latex |
|
18 |
{ |
|
74786 | 19 |
/* index entries */ |
20 |
||
21 |
def index_escape(str: String): String = |
|
22 |
{ |
|
23 |
val special1 = "!\"@|" |
|
24 |
val special2 = "\\{}#" |
|
25 |
if (str.exists(c => special1.contains(c) || special2.contains(c))) { |
|
26 |
val res = new StringBuilder |
|
27 |
for (c <- str) { |
|
28 |
if (special1.contains(c)) { |
|
29 |
res ++= "\\char" |
|
30 |
res ++= Value.Int(c) |
|
31 |
} |
|
32 |
else { |
|
33 |
if (special2.contains(c)) { res += '"'} |
|
34 |
res += c |
|
35 |
} |
|
36 |
} |
|
37 |
res.toString |
|
38 |
} |
|
39 |
else str |
|
40 |
} |
|
41 |
||
42 |
object Index_Item |
|
43 |
{ |
|
44 |
sealed case class Value(text: Text, like: String) |
|
45 |
def unapply(tree: XML.Tree): Option[Value] = |
|
46 |
tree match { |
|
47 |
case XML.Wrapped_Elem(Markup.Latex_Index_Item(_), text, like) => |
|
48 |
Some(Value(text, XML.content(like))) |
|
49 |
case _ => None |
|
50 |
} |
|
51 |
} |
|
52 |
||
53 |
object Index_Entry |
|
54 |
{ |
|
55 |
sealed case class Value(items: List[Index_Item.Value], kind: String) |
|
56 |
def unapply(tree: XML.Tree): Option[Value] = |
|
57 |
tree match { |
|
58 |
case XML.Elem(Markup.Latex_Index_Entry(kind), body) => |
|
59 |
val items = body.map(Index_Item.unapply) |
|
60 |
if (items.forall(_.isDefined)) Some(Value(items.map(_.get), kind)) else None |
|
61 |
case _ => None |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
||
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
66 |
/* output text and positions */ |
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
67 |
|
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
68 |
type Text = XML.Body |
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
69 |
|
74777
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
70 |
def position(a: String, b: String): String = "%:%" + a + "=" + b + "%:%\n" |
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
71 |
|
74777
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
72 |
def init_position(file_pos: String): List[String] = |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
73 |
if (file_pos.isEmpty) Nil |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
74 |
else List("\\endinput\n", position(Markup.FILE, file_pos)) |
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
75 |
|
74777
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
76 |
class Output |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
77 |
{ |
74786 | 78 |
def latex_output(latex_text: Text): String = apply(latex_text) |
79 |
||
74790 | 80 |
def latex_macro0(name: String): Text = |
81 |
XML.string("\\" + name) |
|
82 |
||
74789 | 83 |
def latex_macro(name: String, body: Text): Text = |
84 |
XML.enclose("\\" + name + "{", "}", body) |
|
74786 | 85 |
|
74790 | 86 |
def latex_environment(name: String, body: Text): Text = |
87 |
XML.enclose("%\n\\begin{" + name + "}%\n", "%\n\\end{" + name + "}", body) |
|
88 |
||
74823 | 89 |
def latex_heading(kind: String, body: Text): Text = |
90 |
XML.enclose("%\n\\isamarkup" + kind + "{", "%\n}\n", body) |
|
91 |
||
92 |
def latex_body(kind: String, body: Text): Text = |
|
93 |
latex_environment("isamarkup" + kind, body) |
|
94 |
||
74786 | 95 |
def index_item(item: Index_Item.Value): String = |
96 |
{ |
|
97 |
val like = if (item.like.isEmpty) "" else index_escape(item.like) + "@" |
|
98 |
val text = index_escape(latex_output(item.text)) |
|
99 |
like + text |
|
100 |
} |
|
101 |
||
102 |
def index_entry(entry: Index_Entry.Value): Text = |
|
103 |
{ |
|
104 |
val items = entry.items.map(index_item).mkString("!") |
|
105 |
val kind = if (entry.kind.isEmpty) "" else "|" + index_escape(entry.kind) |
|
106 |
latex_macro("index", XML.string(items + kind)) |
|
107 |
} |
|
108 |
||
109 |
||
110 |
/* standard output of text with per-line positions */ |
|
74784
d2522bb4db1b
symbolic latex_output via XML, interpreted in Isabelle/Scala;
wenzelm
parents:
74783
diff
changeset
|
111 |
|
74777
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
112 |
def apply(latex_text: Text, file_pos: String = ""): String = |
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
113 |
{ |
74777
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
114 |
var line = 1 |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
115 |
val result = new mutable.ListBuffer[String] |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
116 |
val positions = new mutable.ListBuffer[String] ++= init_position(file_pos) |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
117 |
|
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
118 |
def traverse(body: XML.Body): Unit = |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
119 |
{ |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
120 |
body.foreach { |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
121 |
case XML.Text(s) => |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
122 |
line += s.count(_ == '\n') |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
123 |
result += s |
74783 | 124 |
case XML.Elem(Markup.Document_Latex(props), body) => |
125 |
for { l <- Position.Line.unapply(props) if positions.nonEmpty } { |
|
126 |
val s = position(Value.Int(line), Value.Int(l)) |
|
127 |
if (positions.last != s) positions += s |
|
128 |
} |
|
129 |
traverse(body) |
|
74786 | 130 |
case XML.Elem(Markup.Latex_Output(_), body) => |
131 |
traverse(XML.string(latex_output(body))) |
|
74790 | 132 |
case XML.Elem(Markup.Latex_Macro0(name), Nil) => |
133 |
traverse(latex_macro0(name)) |
|
134 |
case XML.Elem(Markup.Latex_Macro(name), body) => |
|
135 |
traverse(latex_macro(name, body)) |
|
136 |
case XML.Elem(Markup.Latex_Environment(name), body) => |
|
137 |
traverse(latex_environment(name, body)) |
|
74823 | 138 |
case XML.Elem(Markup.Latex_Heading(kind), body) => |
139 |
traverse(latex_heading(kind, body)) |
|
140 |
case XML.Elem(Markup.Latex_Body(kind), body) => |
|
141 |
traverse(latex_body(kind, body)) |
|
74786 | 142 |
case Index_Entry(entry) => |
143 |
traverse(index_entry(entry)) |
|
74790 | 144 |
case t: XML.Tree => |
145 |
error("Bad latex markup" + |
|
146 |
(if (file_pos.isEmpty) "" else Position.here(Position.File(file_pos))) + ":\n" + |
|
147 |
XML.string_of_tree(t)) |
|
74777
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
148 |
} |
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
149 |
} |
74777
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
150 |
traverse(latex_text) |
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
151 |
|
74777
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
152 |
result ++= positions |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
153 |
result.mkString |
2fd0c33fe440
clarified signature: Latex.Output as parameter to Document_Build.Engine;
wenzelm
parents:
74748
diff
changeset
|
154 |
} |
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
155 |
} |
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
156 |
|
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73736
diff
changeset
|
157 |
|
67173 | 158 |
/* generated .tex file */ |
159 |
||
67184 | 160 |
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
|
161 |
private val Line_Pattern = """^*%:%(\d+)=(\d+)%:%$""".r |
67173 | 162 |
|
163 |
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
|
164 |
{ |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
165 |
val positions = |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
166 |
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
|
167 |
takeWhile(_ != "\\endinput").reverse |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
168 |
|
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
169 |
val source_file = |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
170 |
positions match { |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
171 |
case File_Pattern(file) :: _ => Some(file) |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
172 |
case _ => None |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
173 |
} |
67173 | 174 |
|
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
175 |
val source_lines = |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
176 |
if (source_file.isEmpty) Nil |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
177 |
else |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
178 |
positions.flatMap(line => |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
179 |
line match { |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
180 |
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
|
181 |
case _ => None |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
182 |
}) |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
183 |
|
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
184 |
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
|
185 |
} |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
186 |
|
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
187 |
final class Tex_File private[Latex]( |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
188 |
tex_file: Path, source_file: Option[String], source_lines: List[(Int, Int)]) |
67173 | 189 |
{ |
190 |
override def toString: String = tex_file.toString |
|
191 |
||
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
192 |
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
|
193 |
source_file match { |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
194 |
case None => None |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
195 |
case Some(file) => |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
196 |
val source_line = |
73359 | 197 |
source_lines.iterator.takeWhile({ case (m, _) => m <= l }). |
198 |
foldLeft(0) { case (_, (_, n)) => n } |
|
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67190
diff
changeset
|
199 |
if (source_line == 0) None else Some(Position.Line_File(source_line, file)) |
67173 | 200 |
} |
201 |
||
202 |
def position(line: Int): Position.T = |
|
67188
bc7a6455e12a
simplified positions -- line is also human-readable in generated .tex file;
wenzelm
parents:
67184
diff
changeset
|
203 |
source_position(line) getOrElse Position.Line_File(line, tex_file.implode) |
67173 | 204 |
} |
205 |
||
206 |
||
207 |
/* latex log */ |
|
208 |
||
73782 | 209 |
def latex_errors(dir: Path, root_name: String): List[String] = |
210 |
{ |
|
211 |
val root_log_path = dir + Path.explode(root_name).ext("log") |
|
212 |
if (root_log_path.is_file) { |
|
213 |
for { (msg, pos) <- filter_errors(dir, File.read(root_log_path)) } |
|
214 |
yield "Latex error" + Position.here(pos) + ":\n" + Library.indent_lines(2, msg) |
|
215 |
} |
|
216 |
else Nil |
|
217 |
} |
|
218 |
||
67173 | 219 |
def filter_errors(dir: Path, root_log: String): List[(String, Position.T)] = |
67172 | 220 |
{ |
67173 | 221 |
val seen_files = Synchronized(Map.empty[JFile, Tex_File]) |
222 |
||
223 |
def check_tex_file(path: Path): Option[Tex_File] = |
|
224 |
seen_files.change_result(seen => |
|
225 |
seen.get(path.file) match { |
|
226 |
case None => |
|
227 |
if (path.is_file) { |
|
228 |
val tex_file = read_tex_file(path) |
|
229 |
(Some(tex_file), seen + (path.file -> tex_file)) |
|
230 |
} |
|
231 |
else (None, seen) |
|
232 |
case some => (some, seen) |
|
233 |
}) |
|
234 |
||
235 |
def tex_file_position(path: Path, line: Int): Position.T = |
|
236 |
check_tex_file(path) match { |
|
237 |
case Some(tex_file) => tex_file.position(line) |
|
238 |
case None => Position.Line_File(line, path.implode) |
|
239 |
} |
|
240 |
||
67172 | 241 |
object File_Line_Error |
242 |
{ |
|
71601 | 243 |
val Pattern: Regex = """^(.*?\.\w\w\w):(\d+): (.*)$""".r |
67173 | 244 |
def unapply(line: String): Option[(Path, Int, String)] = |
67172 | 245 |
line match { |
246 |
case Pattern(file, Value.Int(line), message) => |
|
247 |
val path = File.standard_path(file) |
|
248 |
if (Path.is_wellformed(path)) { |
|
67183 | 249 |
val file = (dir + Path.explode(path)).canonical |
67423 | 250 |
val msg = Library.perhaps_unprefix("LaTeX Error: ", message) |
251 |
if (file.is_file) Some((file, line, msg)) else None |
|
67172 | 252 |
} |
253 |
else None |
|
254 |
case _ => None |
|
255 |
} |
|
256 |
} |
|
257 |
||
67418
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
wenzelm
parents:
67417
diff
changeset
|
258 |
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
|
259 |
val More_Error = |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
260 |
List( |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
261 |
"<argument>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
262 |
"<template>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
263 |
"<recently read>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
264 |
"<to be read again>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
265 |
"<inserted text>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
266 |
"<output>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
267 |
"<everypar>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
268 |
"<everymath>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
269 |
"<everydisplay>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
270 |
"<everyhbox>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
271 |
"<everyvbox>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
272 |
"<everyjob>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
273 |
"<everycr>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
274 |
"<mark>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
275 |
"<everyeof>", |
eb29f4868d14
more error information according to @<Print type of token list@> in pdfweb.tex;
wenzelm
parents:
67194
diff
changeset
|
276 |
"<write>").mkString("^(?:", "|", ") (.*)$").r |
67172 | 277 |
|
73474
4e12a6caefb3
turn LaTeX warning into error, for the sake of isabelle.sty/bbbfont;
wenzelm
parents:
73359
diff
changeset
|
278 |
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
|
279 |
val Bad_File = """^! LaTeX Error: (File `.*' not found\.)$""".r |
67482 | 280 |
|
67423 | 281 |
val error_ignore = |
282 |
Set( |
|
283 |
"See the LaTeX manual or LaTeX Companion for explanation.", |
|
284 |
"Type H <return> for immediate help.") |
|
285 |
||
67418
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
wenzelm
parents:
67417
diff
changeset
|
286 |
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
|
287 |
{ |
71784 | 288 |
val lines1 = |
289 |
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
|
290 |
lines1.zipWithIndex.collectFirst({ |
67423 | 291 |
case (Line_Error(msg), i) => |
292 |
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
|
293 |
} |
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
wenzelm
parents:
67417
diff
changeset
|
294 |
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
|
295 |
lines match { |
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
wenzelm
parents:
67417
diff
changeset
|
296 |
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
|
297 |
case _ => None |
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
wenzelm
parents:
67417
diff
changeset
|
298 |
} |
5a6ed2e679fb
more general error suffixes, e.g. for messages that are broken over several lines;
wenzelm
parents:
67417
diff
changeset
|
299 |
|
67173 | 300 |
@tailrec def filter(lines: List[String], result: List[(String, Position.T)]) |
301 |
: List[(String, Position.T)] = |
|
302 |
{ |
|
67172 | 303 |
lines match { |
67173 | 304 |
case File_Line_Error((file, line, msg1)) :: rest1 => |
67183 | 305 |
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
|
306 |
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
|
307 |
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
|
308 |
case Bad_Font(msg) :: rest => |
4e12a6caefb3
turn LaTeX warning into error, for the sake of isabelle.sty/bbbfont;
wenzelm
parents:
73359
diff
changeset
|
309 |
filter(rest, (msg, Position.none) :: result) |
67483
aae933ca6fbd
tuned message: same error may occur in different contexts;
wenzelm
parents:
67482
diff
changeset
|
310 |
case Bad_File(msg) :: rest => |
67482 | 311 |
filter(rest, (msg, Position.none) :: result) |
67172 | 312 |
case _ :: rest => filter(rest, result) |
313 |
case Nil => result.reverse |
|
314 |
} |
|
67173 | 315 |
} |
67172 | 316 |
|
67174 | 317 |
filter(Line.logical_lines(root_log), Nil) |
67173 | 318 |
} |
67172 | 319 |
} |