PreFigure macros/reusable groups?

14 views
Skip to first unread message

Andrew Scholer

unread,
Sep 24, 2025, 4:58:39 PM (2 days ago) Sep 24
to pretext...@googlegroups.com
Is there a way to define a reusable block in a prefigure element?

I am exploring rendering memory diagrams. For those, I would love to have the notion of a "variable" that consists of a box and two labels - one label outside for the "name" and the other label inside the box for the "value". Instead of copy/pasting the group of elements for each variable, I would 

I don't see a way to make a reusable group of elements like that. The repeat element is too structured for what I want and definitions don't appear capable enough.

Is there a way to do what I am looking for? Or add custom XSL so I can define a new element that gets transformed into a set of elements?

Andrew Scholer
Computer Science Instructor / Program Chair
Chemeketa Community College
Office hour info: https://computerscience.chemeketa.edu/people/andrew-scholer/

David Austin

unread,
Sep 24, 2025, 5:29:32 PM (2 days ago) Sep 24
to pretext...@googlegroups.com
This does not currently exist, but I think it's a good idea, and one that I've thought of before but have needed some prodding to implement.  Can you make a suggestion for the markup that you'd like to see?  One idea would be to have an element that defines the macro and another to drop the macro into the source tree.  In that case, differences from one use to another would be handled by the user namespace.  Or do you need more flexibility?

David

--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pretext-support/CACm44N-Lm_ytKjf2Nrv1duLpfx-%2B8t8K2%3DsuFR27gO2jwLQDRA%40mail.gmail.com.

Andrew Scholer

unread,
Sep 25, 2025, 11:25:51 AM (yesterday) Sep 25
to pretext...@googlegroups.com
I spent some time thinking about possible markup and struggled to come up with something both simple and complete.

A complete approach might be to allow authors to have an xsl "preprocessor" file that is used to transform the authored source into the document the PreFigure python processes. Given that, an author can do any transformation they like. I think once people (OK, me) start trying to define macros they will want to be able to define things more complex than trivial expansions. For example, I might want to be able to author:

<array name="tensCount">
  <el>10</el>
  <el>20</el>
  <el>30</el>
   ...
</array>

And have each el decomposed into a box with an index and value label drawn within a box that is labeled with the array name.

Maybe we can discuss at drop-in and then move discussion to dev?

Andrew

Rob Beezer

unread,
5:15 AM (11 hours ago) 5:15 AM
to pretext...@googlegroups.com
So are you suggesting authors put their own markup into their source and some sort of one-off set of pre-processor instructions are needed to interpret it?
>>> <https://groups.google.com/d/msgid/pretext-support/CACm44N-Lm_ytKjf2Nrv1duLpfx-%2B8t8K2%3DsuFR27gO2jwLQDRA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "PreTeXt support" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to pretext-suppo...@googlegroups.com.
>> To view this discussion visit
>> https://groups.google.com/d/msgid/pretext-support/CANXmVMDbhqEKTLUdk81Lhhq7p%2BigPVW8H8SeWEU4KwEgXVExeg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/pretext-support/CANXmVMDbhqEKTLUdk81Lhhq7p%2BigPVW8H8SeWEU4KwEgXVExeg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

David Austin

unread,
7:13 AM (9 hours ago) 7:13 AM
to pretext...@googlegroups.com
Yes, that sounds good.  Let's discuss at Monday's drop-in.  I'm not sure I have a clear picture of what you're proposing so it would be good to talk through it.

David

Andrew Scholer

unread,
11:14 AM (5 hours ago) 11:14 AM
to pretext...@googlegroups.com
Rob - 

My main goal was something expressive that isn't a new Turing complete DSL PreFigure needs to implement. Which essentially leaves existing languages/markups.

Absent official support, this is likely the avenue I would go down:
  • Write some simple XSL to transform custom elements I want to use (array) into primitives (labels and rectangles).
  • Author my source diagrams using the custom elements.
  • Preprocess my source with the XSL to produce new files I feed into PreFigure
I was thinking that last step would be pretty easy to add into the PreFigure build process. an optional XSL stylesheet that is applied to the raw files before PreFigure does its parsing.

Andrew

Reply all
Reply to author
Forward
0 new messages