Activecode program blocks eat up the last line in preamble/code

1 view
Skip to first unread message

Charilaos Skiadas

unread,
Jun 4, 2025, 4:19:14 PM6/4/25
to prete...@googlegroups.com
Maybe this is a known issue (or expected behavior?) and I missed it, but I’ve noticed that the last line of preamble and code blocks (and apparently the first line in postamble) is getting effectively removed (replaced with an empty line). some examples:

<program interactive="activecode" language="python">
  <code>def __eq__(self, other):
    pass</code>
  <postamble>testing
  something</postamble>
</program>
<program interactive="activecode" language="python">
  <preamble>
def f():
    return 5</preamble>
  <code>f()</code>
</program>
<program interactive="activecode" language="python">
  <code>def __ne__(self, other):
    pass</code>
</program>

The first program ends up showing only   "def __eq__(self, other):”  and then “something” and a newline.
The second program shows only "def f():” and misses both the return and the f().
The third program shows only "def __ne__(self, other):” (followed by a newline)

This is not the case without interactive=“activecode”.  I’m thinking the problem stems from the call to “substring-before-last” here:  https://github.com/PreTeXtBook/pretext/blob/b31d10bd04eebc7387bb1d55b1e64a603533c3e0/xsl/pretext-runestone.xsl#L2092


Charilaos Skiadas
Department of Mathematics
Hanover College


Andrew Scholer

unread,
Jun 4, 2025, 5:05:33 PM6/4/25
to prete...@googlegroups.com
Yes, I have noticed the same issue. And some problems with being able to intentionally author in blank lines at the junctions between <preamble> <code> and <code> and <postamble>.

I have a PR for it here:
https://github.com/PreTeXtBook/pretext/pull/2548

I tested against your samples, it seems to fix up the sample you provide.

Also, in case you are not aware... PreTeXt will do some cleaning of whitespace. So you can have your code start on a new line and indent it within the source (consistently within a particular program) and it will get cleaned up:

<program>
  <preamble>
def f():
    return 5
  </preamble>
  <code>
f()
  </code>
</program>

Or

<program>

  <preamble>
    def f():
        return 5
  </preamble>
  <code>
    f()
  </code>
</program>

Should both produce:
-------------------------------------
def f():
    return 5
f()
-------------------------------------

Andrew Scholer (he/him/his)
Computer Science Instructor
Chemeketa Community College


--
You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pretext-dev/5C00DDFE-1076-4B71-A1DB-A6274240F534%40gmail.com.
Reply all
Reply to author
Forward
0 new messages