--- a/src/Pure/Thy/latex.scala Wed Nov 10 14:10:42 2021 +0100
+++ b/src/Pure/Thy/latex.scala Wed Nov 10 19:45:30 2021 +0100
@@ -10,6 +10,7 @@
import java.io.{File => JFile}
import scala.annotation.tailrec
+import scala.collection.mutable
import scala.util.matching.Regex
@@ -21,14 +22,16 @@
def output(latex_text: Text, file_pos: String = ""): String =
{
- def position(a: String, b: String): String = "%:%" + a + "=" + b + "%:%"
+ var line = 1
+ val result = new mutable.ListBuffer[String]
+ val positions = new mutable.ListBuffer[String]
- var positions: List[String] =
- if (file_pos.isEmpty) Nil
- else List(position(Markup.FILE, file_pos), "\\endinput")
+ def position(a: String, b: String): String = "%:%" + a + "=" + b + "%:%\n"
- var line = 1
- var result = List.empty[String]
+ if (file_pos.nonEmpty) {
+ positions += "\\endinput\n"
+ positions += position(Markup.FILE, file_pos)
+ }
def traverse(body: XML.Body): Unit =
{
@@ -38,18 +41,19 @@
if (markup.name == Markup.DOCUMENT_LATEX) {
for { l <- Position.Line.unapply(markup.properties) if positions.nonEmpty } {
val s = position(Value.Int(line), Value.Int(l))
- if (positions.head != s) positions ::= s
+ if (positions.last != s) positions += s
}
traverse(body)
}
case XML.Text(s) =>
line += s.count(_ == '\n')
- result ::= s
+ result += s
}
}
traverse(latex_text)
- result.reverse.mkString + cat_lines(positions.reverse)
+ result ++= positions
+ result.mkString
}