\version "2.18.2"

#(define-markup-command (single-hbracket layout props arg-for-bracket arg)
  (markup? markup?)
  #:properties ((padding 0)
                (direction UP)
                (right-left-lengthen '(-0.3 . 0.3))
                (potrusion 0.3))
  #:category graphic
  (let* ((th 0.1) ;; todo: take from GROB.
         (m (interpret-markup layout props arg))
         (stil-add (interpret-markup layout props arg-for-bracket)))

   (define
     (add-bracket-to-stencil
       stil add-to-bracket-stil
       axis thick
       protrusion direction
       right-left-lengthen padding)
    "Add a bracket to @var{stil}, producing a new stencil."
    (let* ((ext
             (coord-translate
               (ly:stencil-extent stil axis)
               right-left-lengthen))
           (other-axis (lambda (a) (remainder (+ a 1) 2)))
           (bracket (ly:bracket axis ext thick (* -1 direction  protrusion)))
           (bracket-length
             (interval-length (ly:stencil-extent bracket X)))
           (bracket
             (ly:stencil-add
               bracket
               (stencil-whiteout
                 (ly:stencil-translate-axis
                   (centered-stencil add-to-bracket-stil)
                   (+ (/ bracket-length 2) (car right-left-lengthen))
                   X)))))
      (ly:stencil-combine-at-edge
        stil
        (other-axis axis)
        direction
        bracket
        padding)))

    (add-bracket-to-stencil
      m stil-add
      X th
      (+ potrusion (* 2.5 th)) direction
      right-left-lengthen (+ padding th))))

%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLES
%%%%%%%%%%%%%%%%%%%%%%%%%


%\markup {
%  one two three
%
%  \single-hbracket " 3 " \line { one two three }
%
%
%  \override #'(direction . 1)
%  \single-hbracket \tiny \italic " 3 " oneoneone
%
%
%  \override #'(padding . 3)
%  \single-hbracket
%    \concat {
%    	    " 3 "
%    	    \raise #0.7
%    	      \override #'(style . mensural) \note #"breve" #1
%    	    \hspace #0.7
%    }
%    twotwotwo
%
%
%  \override #'(right-left-lengthen . (1 . -1))
%  \override #'(potrusion . 1.2)
%  \single-hbracket " 3:2 " threethreethree
%}

#(use-modules (ice-9 regex))

#(define-markup-command (underdot layout props arg)
  (markup?)
"Place a dot below @var{arg} using @code{\\center.column}"
    (interpret-markup layout props
      (markup #:override '(baseline-skip . 0.5) #:center-column (arg "."))))

#(define-markup-command (emphasize layout props strg)(string?)
#:properties ((func make-underdot-markup)
              (indicator "*"))
"Applies @code{func} to substrings of @var{strg}.  Those substrings have to be
marked with @code{indicator}, which defaults to @code{"*"}

@lilypond[verbatim,quote]
\\markup \\column {
  \\emphasize #"a*ä**ö*de*f**ü*"
  \\override #'(indicator . "_") \\emphasize #"a_ä__ö_de_f__ü_"
  \\override #`(func . ,make-underline-markup) \\emphasize #"a*ä**ö*de*f**ü*"
}
@end lilypond
"
  (let* ((indicator-char
           (let ((ls (string->list indicator)))
             (if (not (= (length ls) 1))
                 (ly:error
                   "indicator needs to be (= (string-length indicator) 1)")
                 (car ls))))
         (sub-strings
           (map (lambda(x) (match:substring x 1))
             (list-matches
               (string-concatenate
                 (list (regexp-quote (string indicator-char)) "([^" (regexp-quote (string indicator-char)) "]*)" (regexp-quote (string indicator-char))))
               strg)))
         (strg-ls (string-split strg indicator-char))
         (mrkp
           (make-concat-markup
             (map
               (lambda (x)
                 (if (member x sub-strings)
                     (func x)
                     x))
               strg-ls))))
    (interpret-markup layout props mrkp)))


dot = \markup { \fontsize #-3 • }


vertLine =
\markup \stencil
#(make-connected-path-stencil
  '((0 2.1)  ;; path coordinates
    (0 -0.3))
  0.2  ;; line thickness
  1  ;; X-axis scaling factor
  1  ;; Y-axis scaling factor
;  0.75  ;; Y-axis scaling factor
  #f  ;; auto-connect path to origin point? (0 0)
  #f) % filled path?
vertSepalt = \markup { \hspace #0.5 \vertLine \hspace #0.5 }

vertLineDot =
\markup \stencil
#(make-connected-path-stencil
  '((0 2.1)  ;; path coordinates
    (0 0))
  0.2  ;; line thickness
  1  ;; X-axis scaling factor
  1  ;; Y-axis scaling factor
;  0.75  ;; Y-axis scaling factor
  #f  ;; auto-connect path to origin point? (0 0)
  #f) % filled path?
vertSepDotalt = \markup { \hspace #0.5 \combine \underdot \vertLineDot \hspace #1 }

vertSep = \markup { \general-align #Y #-0.7 \scale #'(1.0 . 1.615) "|" }
vertSepDot = \markup {
  \general-align #Y #-0.6
  \center-column {
    \scale #'(1.0 . 1.44) "|"
    \translate-scaled #'(0 . 2.6)
    "."
  }
}
