An output policy for the three commands, and @cond as a true special form
A snapshot of the development tree. The substantial changes since the last one:
COMMAND OUTPUT POLICY. The three commands display text in exactly three cases,
and each owns a stream: LOGGING under "-v" greater than 0 and an ERROR before
termination go to STDERR; OUTPUT THE USER ASKED FOR goes to STDOUT. For ktext
that output is a document, so "ktext doc.kt -d | ..." is now safe -- logging
used to share the stream and land inside the document. A bare command prints
its usage and succeeds rather than failing. Colour is emitted only to a
terminal, per stream, and NO_COLOR is honoured.
"-v 1" reports every decision whose outcome you could not have read off your own
input: the klammerset that was loaded and from which file, a font's directory, a
":files" name's file, how "-o" was expanded. Higher levels are the trace.
The commands no longer warn and continue: an anomaly is an error, described with
its location. Two exceptions remain, each for a stated reason -- a condition
that is expected and temporary by design, and a judgment that is a heuristic
rather than exact.
@cond IS NOW A TRUE SPECIAL FORM, resolved at APPLICATION time rather than when
the file is read. Two consequences for a writer:
* a state variable reaches the predicate. "@@@state Flag :value true @@@
@cond *Flag* | T | F @" renders "T"; it used to see the literal "*Flag*" and
silently take the false branch. The document now behaves like a klammer
body, whose arguments are bound before its conditionals are decided.
* nothing in a discarded branch happens -- it is not read, not evaluated, not
expanded. An @eval in the branch not taken used to run anyway.
Its predicate relation is total and strict: true, True, 1; false, False, 0, and
empty; anything else is an error at the @cond rather than silently false.
@eval REACHING OUTSIDE. ":shell" and ":haskell" now keep the command's standard
error out of the document (it appears under "-v 1") and treat a nonzero exit as
an error naming what the command reported. A command that exits nonzero on
purpose -- "grep" finding no match -- says so with "|| true".
KLAMMER SETS. Several combine: "--klammersets a b c" loads all three in the
order given, sharing one namespace, with the definition modes deciding
collisions. "none" means none and may not be combined with other symbols. A
klammerset with symbol X is declared in a file X/X.k, which is what lets two
sets require the same third set without loading it twice.
TESTS. Four new suites: the kdiag command's interface, the @eval primitive's
contract with the outside world, and verbosity at both tiers. Three suites
that could not run on macOS at all now do.
Assembled from dev commit 6c8ee6c22fca.
This commit is contained in:
@@ -29,7 +29,6 @@ def is_comment(s):
|
||||
return s.strip().startswith("//")
|
||||
|
||||
def split_blocks(s):
|
||||
kutil.msg()
|
||||
blocks = []
|
||||
in_code = True
|
||||
block = ""
|
||||
@@ -53,7 +52,6 @@ def split_blocks(s):
|
||||
return blocks
|
||||
|
||||
def get_lines(comment, code, n):
|
||||
kutil.msg()
|
||||
lines = code.split("\n")
|
||||
if len(lines) < n:
|
||||
raise Exception(
|
||||
@@ -64,7 +62,6 @@ def get_lines(comment, code, n):
|
||||
return ("\n".join(lines[:n]), "\n".join(lines[n:]))
|
||||
|
||||
def parse_blocks(blocks):
|
||||
kutil.msg()
|
||||
box_comment_rgx = re.compile("\\s*//(\\d+)\\s+.*", re.S)
|
||||
i = 0
|
||||
block_pairs = []
|
||||
|
||||
@@ -30,6 +30,12 @@ std::string document(Machine& machine)
|
||||
// width check (tex_width_check() in table.py) left in the xelatex log,
|
||||
// followed by a short :column_width primer. Plain line scanning -- no
|
||||
// std::regex over the (arbitrarily large) log text.
|
||||
// One of the two surviving WARNINGS (see the output policy in CLAUDE.md; the
|
||||
// other is warn_unparsed_katoms). It stays a warning because the judgment is
|
||||
// a HEURISTIC and a question of layout QUALITY rather than well-formedness:
|
||||
// the check carries a 2pt tolerance for exactly-full tables, and a document
|
||||
// with one over-wide table still renders. Halting would turn a false positive
|
||||
// into a blocker. Promote it to an error when the measurement is exact.
|
||||
static void warn_wide_tables(const std::string& xelatex_log)
|
||||
{
|
||||
bool any = false;
|
||||
|
||||
@@ -149,12 +149,19 @@ fs::path parse_input_filename(const std::string& s, const std::string& input_dir
|
||||
// (K_input_dir), so a document renders identically wherever ktext is
|
||||
// run from; then the legacy kt/ subdirectory; a name found in neither
|
||||
// is returned as given (cwd-relative) and errors downstream.
|
||||
// Which of the three a name landed on is a DERIVED value -- the ".kt" may
|
||||
// have been supplied, and the directory certainly was -- so "-v 1" reports
|
||||
// it. A ":files chapter1" that quietly found kt/chapter1.kt rather than
|
||||
// the file beside the document is exactly what the author cannot see.
|
||||
fs::path in_input_dir = fs::path(input_dir) / p;
|
||||
if (file_exists(in_input_dir.string())) {
|
||||
(void)K::log(1, "Input file \"" + s + "\": " + in_input_dir.string());
|
||||
return in_input_dir;
|
||||
}
|
||||
fs::path in_kt_dir = fs::path(input_dir) / "kt" / p;
|
||||
if (file_exists(in_kt_dir.string())) {
|
||||
(void)K::log(1, "Input file \"" + s + "\": " + in_kt_dir.string()
|
||||
+ " (found in the kt/ subdirectory)");
|
||||
return in_kt_dir;
|
||||
}
|
||||
return p;
|
||||
@@ -171,7 +178,10 @@ void write_file(const std::string& filename, const std::string& contents, bool w
|
||||
if (write_p) {
|
||||
string_to_file(filename, contents);
|
||||
} else {
|
||||
msg() << "Output filename: " << filename << "\n";
|
||||
// Not writing: name the file that would have been written. A
|
||||
// derived value, so "-v 1" -- and never on stdout, which carries
|
||||
// the document itself.
|
||||
(void)K::log(1, "Output filename:", filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -190,7 +190,9 @@ std::string Document_class::create_html_output_directories()
|
||||
m_cache_dir = cache_directory("_html_pages");
|
||||
if (m_no_cache && fs::exists(m_cache_dir)) {
|
||||
for (auto& entry : std::filesystem::directory_iterator(m_cache_dir)) {
|
||||
msg() << " Removing cache directory: " << entry << "\n";
|
||||
// What ":cache false" actually removed: a derived consequence of
|
||||
// an option, so "-v 1".
|
||||
(void)K::log(1, "Removing cache directory:", entry.path().string());
|
||||
std::filesystem::remove_all(entry);
|
||||
}
|
||||
}
|
||||
@@ -696,12 +698,16 @@ std::string Document_class::make_single_html_page(const std::string& output_dire
|
||||
std::string Document_class::make_html_navigation_structure(
|
||||
const std::string& output_directory, std::vector<Heading> headings)
|
||||
{
|
||||
msg() << "Navigation format\n";
|
||||
// Which structure path was taken is a DERIVED fact -- ":structure book"
|
||||
// chose it -- so it belongs at "-v 1". It was a msg(), which printed it
|
||||
// to stdout on every book render, ahead of the document.
|
||||
(void)K::log(1, "Navigation format");
|
||||
std::vector<std::string> pages_basenames {};
|
||||
|
||||
for (auto [basename, page_text] : m_file_components) {
|
||||
pages_basenames.push_back(basename);
|
||||
msg() << basename << ": " << abbrev(page_text, 96) << "\n";
|
||||
// A trace of the work, not a decision: verbosity 3.
|
||||
(void)K::log(3, basename + ": " + abbrev(page_text, 96));
|
||||
}
|
||||
std::string pages_basenames_filename = m_cache_dir + "/_pages_basenames.js";
|
||||
write_basenames_js_file(pages_basenames_filename, pages_basenames);
|
||||
|
||||
@@ -71,17 +71,13 @@ namespace latex {
|
||||
std::string test = trim(title + subtitle + author + date + version);
|
||||
std::stringstream ss {};
|
||||
if (!test.empty()) {
|
||||
// ss << Pagestyle?
|
||||
std::string full_title = title;
|
||||
if (!full_title.empty() && !subtitle.empty()) {
|
||||
full_title += " --- " + subtitle;
|
||||
}
|
||||
ss << title_line(full_title, "1.8", "8pt")
|
||||
ss << "\\thispagestyle{empty}\n";
|
||||
ss << title_line(title, "1.8", "6pt")
|
||||
<< title_line(subtitle, "1.5", "16pt", true)
|
||||
<< title_line(author)
|
||||
<< title_line(date)
|
||||
<< title_line(version)
|
||||
<< "\n";
|
||||
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user