def output_name(name: String): String = if (name.exists(output_name_map.keySet)) {
Library.string_builder() { res => for (c <- name) {
output_name_map.get(c) match { case None => res += c case Some(s) => res ++= s
}
}
}
} else name
/* index entries */
def index_escape(str: String): String = { val special1 = "!\"@|" val special2 = "\\{}#" if (str.exists(c => special1.contains(c) || special2.contains(c))) {
Library.string_builder() { res => for (c <- str) { if (special1.contains(c)) {
res ++= "\\char"
res ++= Value.Int(c)
} else { if (special2.contains(c)) { res += '"'}
res += c
}
}
}
} else str
}
object Index_Item { sealedcaseclass Value(text: Text, like: String) def unapply(tree: XML.Tree): Option[Value] =
tree match { case XML.Wrapped_Elem(Markup.Latex_Index_Item(_), text, like) =>
Some(Value(text, XML.content(like))) case _ => None
}
}
object Index_Entry { sealedcaseclass Value(items: List[Index_Item.Value], kind: String) def unapply(tree: XML.Tree): Option[Value] =
tree match { case XML.Elem(Markup.Latex_Index_Entry(kind), body) => val items = body.map(Index_Item.unapply) if (items.forall(_.isDefined)) Some(Value(items.map(_.get), kind)) else None case _ => None
}
}
/* tags */
object Tags {
enum Op { case fold, drop, keep }
val standard = "document,theory,proof,ML,visible,-invisible,important,unimportant"
def latex_tag(name: String, body: Text, delim: Boolean = false): Text = { val s = output_name(name) val kind = if (delim) "delim"else"tag" val end = if (delim) ""else"{\\isafold" + s + "}%\n" if (options.bool("document_comment_latex")) {
XML.enclose( "%\n\\begin{isa" + kind + s + "}\n", "%\n\\end{isa" + kind + s + "}\n" + end, body)
} else {
XML.enclose( "%\n\\isa" + kind + s + "\n", "%\n\\endisa" + kind + s + "\n" + end, body)
}
}
def cite(inner: Bibtex.Cite.Inner): Text = { val body =
latex_macro0(inner.kind) :::
(if (inner.location.isEmpty) Nil else XML.string("[") ::: inner.location ::: XML.string("]")) :::
XML.string("{" + inner.citations + "}")
if (inner.pos.isEmpty) body else List(XML.Elem(Markup.Latex_Output(inner.pos), body))
}
def index_item(item: Index_Item.Value): String = { val like = if_proper(item.like, index_escape(item.like) + "@") val text = index_escape(latex_output(item.text))
like + text
}
def index_entry(entry: Index_Entry.Value): Text = { val items = entry.items.map(index_item).mkString("!") val kind = if_proper(entry.kind, "|" + index_escape(entry.kind))
latex_macro("index", XML.string(items + kind))
}
/* standard output of text with per-line positions */
def make(
latex_text: Text,
file_pos: String = "",
line_pos: Properties.T => Option[Int] = Position.Line.unapply
): String = { var line = 1 val result = new mutable.ListBuffer[String] val positions = mutable.ListBuffer.from(init_position(file_pos))
val file_position = if (file_pos.isEmpty) Position.none else Position.File(file_pos)
def traverse(xml: XML.Body): Unit = {
xml.foreach { case XML.Text(s) =>
line += Library.count_newlines(s)
result += s case elem @ XML.Elem(markup, body) => val a = Markup.Optional_Argument.get(markup.properties)
traverse {
markup match { case Markup.Document_Latex(props) => if (positions.nonEmpty) { for (l <- line_pos(props)) { val s = position(Value.Int(line), Value.Int(l)) if (positions.last != s) positions += s
}
}
body case Markup.Latex_Output(_) => XML.string(latex_output(body)) case Markup.Latex_Macro0(name) if body.isEmpty => latex_macro0(name, a) case Markup.Latex_Macro(name) => latex_macro(name, body, a) case Markup.Latex_Environment(name) => latex_environment(name, body, a) case Markup.Latex_Heading(kind) => latex_heading(kind, body, a) case Markup.Latex_Body(kind) => latex_body(kind, body, a) case Markup.Latex_Delim(name) => latex_tag(name, body, delim = true) case Markup.Latex_Tag(name) => latex_tag(name, body) case Markup.Latex_Cite(_) =>
elem match { case Bibtex.Cite(inner) => cite(inner) case _ => unknown_elem(elem, file_position)
} case Markup.Latex_Index_Entry(_) =>
elem match { case Index_Entry(entry) => index_entry(entry) case _ => unknown_elem(elem, file_position)
} case _ => unknown_elem(elem, file_position)
}
}
}
}
traverse(latex_text)
val source_file =
positions match { case File_Pattern(file) :: _ => Some(file) case _ => None
}
val source_lines = if (source_file.isEmpty) Nil else
positions.flatMap(line =>
line match { case Line_Pattern(Value.Int(line), Value.Int(source_line)) => Some(line -> source_line) case _ => None
})
new Tex_File(tex_file, source_file, source_lines)
}
def source_position(l: Int): Option[Position.T] =
source_file match { case None => None case Some(file) => val source_line =
source_lines.iterator.takeWhile({ case (m, _) => m <= l }).
foldLeft(0) { case (_, (_, n)) => n } if (source_line == 0) None else Some(Position.Line_File(source_line, file))
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.