I would like to make enabeling FormatMathJax in the jFriCAS frontend
simpler. It should work like this:

setFormat!(FormatMathJax)
)set output formatted on

In fact, the attached package would do exactly that, BUT
I cannot call it like above.

(11) -> setFormat!(FormatMathJax)
   There are 1 exposed and 0 unexposed library operations named
      setFormat! having 1 argument(s) but none was determined to be
      applicable. Use HyperDoc Browse, or issue
                           )display op setFormat!
      to learn more about the available operations. Perhaps
      package-calling the operation or using coercions on the arguments
      will allow you to apply the operation.

   Cannot find a definition or applicable library operation named
      setFormat! with argument type(s)
                                    Type

      Perhaps you should use "@" to indicate the required return type,
      or "$" to specify which version of the function you need.

(11) -> setFormat!(FormatMathJax pretend FormatterCategory)
                                                        Type: Void

(12) -> 1/sqrt(5)

          +-+
         \|5
   (12)  ----
           5
--FORMAT:BEG:FormatMathJax
\[
\frac{\sqrt{5}}{5}
\]
--FORMAT:END:FormatMathJax

Of course, it is not very user-friendly to require a pretend. And it
makes this simple switch quite long.

Obviously, the interpreter does not recognise the type of FormatMathJax
as the category FormatterCategory, but only as Type.

So I programmed fmtjfricastype.spad.

Instead of

    setFormat!: FormatterCategory -> Void

I now use

    setFormat!: Type -> Void

with that

  setFormat!(FormatMathJax)

works perfectly in a FriCAS session.

However, I find it a bit sad that in setFormat! I have to accept ALL
types. Can I at least check that the input is indeed of category
FormatterCategory even though I use

    setFormat!: Type -> Void

otherwise it looks pretty type-unsafe.

Which way should I follow?


Second question.
At the same time as setFormat! is called, it should switch on this
format, i.e. do the equivalent of

  )set output formatted on

How can I program this from within a .spad file.

Ralf

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/fb6ee49d-8bb3-3cd9-1031-54f0b23bf576%40hemmecke.org.
)abbrev package JFRICAS JFriCASSupport
++ The package \spad{JFriCASSupport} provides a number of
++ service functions to more easily switch on/off certain formats, in
++ particular the use of the FormatMathJax formatter.
JFriCASSupport: Exports == Implementation where
  OFC ==> OutputFormatterCategory
  Exports ==> OFC with
    setFormat!: FormatterCategory -> Void
      ++ \spad{setFormat! f} returns \spad{setFormats! [f]}.
    setFormats!: List FormatterCategory -> Void
      ++ \spad{setFormats!(l)} takes a list \spad{l} of formatters and
      ++ sets this for future output in a session.
      ++ It also issues a command equivalent to ")set output formatted on"
      ++ if the given list is non-empty and ")set output formatted off"
      ++ if the input list is empty.
  Implementation ==> add
    S ==> String
    BOX ==> OutputBox
    setFormats!(lf: List FormatterCategory): Void ==
        for f in lf repeat
            -- get the name of the domain f
            -- see UnivariatePolynomialCategoryFunctions2
            n: String := string CAR(devaluate(f)$Lisp)$Lisp
            b: BOX := box concat("--FORMAT:BEG:", n)
            e: BOX := box concat("--FORMAT:END:", n)
            setDefault!(_
                (s: S): BOX +-> vconcat([b, defaultPrologue(s)$f],1,-1)$BOX,_
                (s: S): BOX +-> vconcat([defaultEpilogue(s)$f, e],1,-1)$BOX_
              )$Formatter(f);
        setFormats!([Formatter f for f in lf] pretend List(OFC))$FormattedOutput
    setFormat!(f: FormatterCategory): Void == setFormats!([f])
)abbrev package JFRICAS JFriCASSupport
++ The package \spad{JFriCASSupport} provides a number of
++ service functions to more easily switch on/off certain formats, in
++ particular the use of the FormatMathJax formatter.
JFriCASSupport: Exports == Implementation where
  OFC ==> OutputFormatterCategory
  Exports ==> OFC with
    setFormat!: Type -> Void
      ++ \spad{setFormat! f} returns \spad{setFormats! [f]}.
    setFormats!: List Type -> Void
      ++ \spad{setFormats!(l)} takes a list \spad{l} of formatters and
      ++ sets this for future output in a session.
      ++ It also issues a command equivalent to ")set output formatted on"
      ++ if the given list is non-empty and ")set output formatted off"
      ++ if the input list is empty.
  Implementation ==> add
    S ==> String
    BOX ==> OutputBox
    setFormats!(lf: List Type): Void ==
        for x in lf repeat
            -- get the name of the domain f
            -- see UnivariatePolynomialCategoryFunctions2
            f: FormatterCategory := x pretend FormatterCategory
            n: String := string CAR(devaluate(f)$Lisp)$Lisp
            b: BOX := box concat("--FORMAT:BEG:", n)
            e: BOX := box concat("--FORMAT:END:", n)
            setDefault!(_
                (s: S): BOX +-> vconcat([b, defaultPrologue(s)$f],1,-1)$BOX,_
                (s: S): BOX +-> vconcat([defaultEpilogue(s)$f, e],1,-1)$BOX_
              )$Formatter(f);
        setFormats!([Formatter(f pretend FormatterCategory) for f in lf] pretend List(OFC))$FormattedOutput
    setFormat!(f: Type): Void == setFormats!([f])

Reply via email to