Skip to Content.
Sympa Menu

texmacs-users - [TeXmacs] style sheet language value typing

Subject: mailing-list for TeXmacs Users

List archive

[TeXmacs] style sheet language value typing


Chronological Thread 
  • From: Kyle Andrews <address@hidden>
  • To: "address@hidden" <address@hidden>
  • Subject: [TeXmacs] style sheet language value typing
  • Date: Sat, 4 Aug 2018 00:40:36 -0400

Dear TeXmacs users,

I am trying to learn the style sheet language by implementing a simple macro called nth. The goal of this macro is to transform 1 and 1st, 2 into 2nd, 3 into 3rd, and 4 into 4th, and so on. The code is shown below.

<assign|last-character|<macro|expr|<with|n|<length|<arg|expr>>|<range|<arg|expr>|<minus|<value|n>|1>|<value|n>>>>>

<assign|nth|<macro|n|<with|d|<last-character|<arg|n>>|<case|<equal|<arg|d>|1>|<arg|n><rsup|st>|<equal|<arg|d>|2>|<arg|n><rsup|nd>|<equal|<value|d>|3>|<arg|n><rsup|rd>|<arg|n><rsup|th>>>>>

It seems like it should work, but I'm missing something fundamental in my understanding about how the style sheet macro language does value typing. I tried taking <minus|5|<last-character|42>>, and got <error|bad plus/minus>. When I tried to compare equality, I got false. Clearly these things are being interpreted by the parser in a way I don't understand.

I tried searching for some documentation about this kind of thing in the manual, but so far haven't had any luck. I would appreciate any pointers from the community.

Best Regards,

Kyle


P.S.

Here is a nicer scheme-like representation fo the macro code:

(document
 (assign "last-character"
     (macro "expr"
        (with "n" (length (arg "expr"))
              (range (arg "expr")
                 (minus (value "n") "1")
                 (value "n")))))
 
 (assign "nth"
     (macro "n"
        (with "d" (last-character (arg "n"))
              (case (equal (arg "d") "1") (concat (arg "n") (rsup "st"))
                (equal (arg "d") "2") (concat (arg "n") (rsup "nd"))
                (equal (value "d") "3") (concat (arg "n") (rsup "rd"))
                (concat (arg "n") (rsup "th")))))))




Archive powered by MHonArc 2.6.19.

Top of Page