I got bored and wanted to write a paper (and then abandon it); but I dislike all these complex typesetter programs. I made one in Common Lisp:

(defun parse-text (elm writer-mode)
  "Converts a high-level text list into string usable for a platform (like terminals). The element can be a string or a list of a text-function along with the parameters.

If the element is a string, return the string.
If the element is a list; retrieve the CAR's writers property. `writers` is a property list of functions that are assigned to symbols that note a function to write string output for a specific environment. The function selected is based on `writer-mode`."
  (cond
    ((stringp elm) elm)
    ((listp elm)
     (apply (getf (getf (eval (car elm)) 'writers) writer-mode) (cdr elm)))
    (t t)
    )
  )

and… that’s it. This is how to make an effective typesetter. It’s efficient and extensible. I spent under 20 minutes on that function.

here are some text-functions to add bold, italics, and underlines for terminals. These are property lists which store information about the text-function and the functions to return strings for each writer-mode.

(setq bold `(documentation "Formats text in bold." writers (terminal ,(lambda (&rest strings) (apply #'concatenate (append '(string "") strings (list "")))  ))))
(setq italic `(documentation "Formats text in italic." writers (terminal ,(lambda (&rest strings) (apply #'concatenate (append '(string "") strings (list ""))) ))))
(setq underline `(documentation "Formats text in underline." writers (terminal ,(lambda (&rest strings) (apply #'concatenate (append '(string "") strings (list ""))) ))) )

Example Usage

The input consists of a list or string so:

(dolist (text `("Lorem ipsum dat..." (underline "The bouregoisie will crumble!") (bold "The proletariat shall rise!")))
  (format *standard-output* (parse-text text 'terminal))
  )

The output will be: Lorem ipsum dat…^[The bouregoisie will crumble!^[^[The proletariat shall rise!^[


I spent more time on failing to make a macro and the documentation than I spent on the actual design. lol