\version "2.18.0"

#(define-public (fraction-or-string? x)
  (or
    (and (pair? x)
         (index? (car x)) (index? (cdr x)))
    (string? x)))
    
#(define (single-time-sig ls arg)
;; Returns a markup to use as a single new TimeSignature.
;; Supported are fractions and strings for use with \musicglyph.
;; If fraction is printed, it's possible to customize baseline-skip and 
;; font-size values taken from 'ls', which should have length 2.
;; If ls-length doesn't fit, a warning appears and an empty markup will be 
;; returned.
 (cond ((< (length ls) 2)
        (begin
          (ly:warning "List ~a is too short, returning empty-markup" ls)
          empty-markup))
       ;; better be paranoid
       ((not (fraction-or-string? arg))
        (begin
          (ly:warning  "~a is neither fraction nor string, ignoring" arg)
          empty-markup))
       ((fraction? arg)
         #{ 
            \markup
              \vcenter
              \number
              \override #`(baseline-skip . ,(car ls))
              \override #`(font-size . ,(cadr ls))
              \center-column {  
                 #(number->string (car arg))
                 #(number->string (cdr arg))
              } 
         #})
       ((string? arg)
        #{ \markup \musicglyph #(format "timesig.~a" arg) #})
       ;; better be paranoid
       (else empty-markup)
        ))
     
customTimeSig =
#(define-music-function (parser location baseline-fontsize sig-1 sig-2 )
    ((number-list? '(0 0)) fraction-or-string? fraction-or-string?)
"
 Returns a double @code{TimeSignature}.
 Fractions or Symbols are possible output.
 If Symbols are wanted "\"timesig."\" has to be omitted.
 @code{font-size} and @code{baseline-skip} are customizeable using the optional 
 @var{baselne-fontsize}-argument
 @var{baselne-fontsize} has to be a list of length 2
 For changing font-size of a TimeSig-Symbol an additional external override 
 should be applied.
"
#{
  \once	\override Staff.TimeSignature.stencil =
    #(lambda (grob)
       (grob-interpret-markup grob
         #{
           \markup 
             \line { 
             	     #(single-time-sig baseline-fontsize sig-1) 
             	     #(single-time-sig baseline-fontsize sig-2) 
             }
         #}))
#})

%%%%%%%%%%%%%%%%%%%%%
% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%

%% paper-, header-, layout-settings for nicer output
ly-version = 
  #(string-append "Engraved by LILYPOND, Version " (lilypond-version))

compiling-time = 
  #(string-append 
    "compiled at " 
    (strftime "%Y-%m-%d %H:%M:%S" (localtime (current-time))))
    
\paper { 
  indent = 0 
  markup-system-spacing #'padding = #6
  top-markup-spacing #'padding = #4
  oddHeaderMarkup = 
    \markup \fontsize #-2 \fill-line { \ly-version \compiling-time }
}

\header {
  title = "Customizing Double TimeSignatures" 
}

\layout {
  \context {
    \Score
    \override RehearsalMark.self-alignment-X = #LEFT
    \override RehearsalMark.font-series = #'bold
    \override RehearsalMark.font-size = -2
    \override RehearsalMark.padding = 3
    \override RehearsalMark.break-align-symbols = #'(left-edge)
    \override BarNumber.stencil = ##f
  }
  \context {
   \Score
   \override TimeSignature.break-visibility = ##(#f #t #t)
  }
}

%little helper:
printTS =
  \once \override Staff.TimeSignature.stencil = #ly:time-signature::print

%% The music
m-four = 
  \relative c' {
    \time 4/4
    c4 d e f
  }

m-six = 
  \relative c' {
    \time 6/4
    c4 d e f e d
    \break
  }

m = { \m-four \m-six }

%% The example
\new Staff \with { \override TimeSignature.stencil = ##f }
  \relative c' {  
    \mark "default"
    \printTS \m-four
    \printTS \m-six
    
    \mark "customTimeSig using fractions"
    \customTimeSig 4/4 6/4
    \m
    
    \mark "customTimeSig using fraction and glyph"
    \customTimeSig "C22" 6/4
    \m
    
    \mark "customTimeSig using fraction, glyph and other font-name"
    \once \override Staff.TimeSignature.font-name = "Verdana"
    \customTimeSig "C22" 6/4
    \m
    
    \mark "using fraction, glyph and other font-name, customizing font-size"
    \once \override Staff.TimeSignature.font-name = "Verdana"
    \customTimeSig #'(0 2) 6/4 "C22" 
    \m
    
    \mark "using fraction, glyph and other font-name, customizing baseline-skip"
    \once \override Staff.TimeSignature.font-name = "ComicSans MS"
    \customTimeSig #'(2.2 0) 6/4 "C22" 
    \m
    
    \mark "time-sigs for ancient music"
    \customTimeSig "neomensural22" "neomensural64"
    \m 
    
    \mark "default again"
    \revert Staff.TimeSignature.stencil
    \m
  }
