(defvar LaTeX-letgut-key-val-options
  '(("draft"  ("true" "false"))
    ("final"  ("true" "false"))
    ("screen" ("true" "false"))
    ("paper"  ("true" "false"))
    ("number")
    ("date")
    ("membership-reminder"  ("true" "false"))
    ("editorial" ("true" "false"))
    ("informations" ("true" "false")))
  "Key=value options for letgutsetup macro.")

(defun LaTeX-letgut-key-val-options ()
  "Return an updated list of key=vals from letgut class."
  (append
   (let ((keys '("pagecolor" "allcolorslinks"))
         (colors (mapcar #'car (LaTeX-xcolor-definecolor-list)))
         result)
     (dolist (key keys result)
       (push (list key colors) result)))
   LaTeX-letgut-key-val-options))

(TeX-add-style-hook
 "letgut"
 (lambda ()
   (TeX-add-to-alist 'LaTeX-provided-package-options
                     '(("mathtools" "fleqn")
                       ("xcolor" "table")
                       ("babel" "english" "french")
                       ("varioref" "nospace" "french")
                       ("biblatex" "sorting=none" "datamodel=letgut" "citestyle=letgut")
                       ("cleveref" "french")))
   (TeX-run-style-hooks
    "article"
    "art11"
    "fontspec"
    "microtype"
    "parskip"
    "fancyhdr"
    "geometry"
    "graphicx"
    "array"
    "etoc"
    "enumitem"
    "titlesec"
    "fourier-orns"
    "placeins"
    "fancyvrb"
    "booktabs"
    "csquotes"
    "mathtools"
    "accsupp"
    "siunitx"
    "hologo"
    "xcolor"
    "tcolorbox"
    "refcount"
    "ninecolors"
    "tabularray"
    "babel"
    "varioref"
    "eurosym"
    "listings"
    "floatrow"
    "biblatex"
    "acro"
    "hyperref"
    "hypcap"
    "cleveref")

   (LaTeX-add-enumitem-newlists
    '("ctannews" "description"))

   (LaTeX-add-xcolor-definecolors
    "letgut_pagecolor"
    "letgut_allcolors_links")

   (LaTeX-add-tcolorbox-tcbuselibraries
    "listings,xparse,breakable,skins,hooks")

   (LaTeX-add-floatrow-DeclareNewOptions
    '("\\DeclareMarginSet{hangleft}" "MarginSet" "hangleft"))

   (TeX-add-symbols

    '("letgutsetup" (TeX-arg-key-val (LaTeX-letgut-key-val-options)))

    "gutenberg"
    "gut"
    "lettre"
    "lettregut"
    "Cahier"
    "Cahiers"
    "letgut"
    "letgutcls"
    "knuth"
    "lamport"
    "tugboat")

   (LaTeX-section-list-add-locally '(("title" 0)
                                     ("subtitle" 1)))

   (LaTeX-add-environments
    '("bookreview" LaTeX-env-args
      (TeX-arg-key-val (("title")
                        ("reviewer")
                        ("bibkey")
                        ("frontcover")
                        ("price"))))
    '("ltx-code" LaTeX-env-args
      [TeX-arg-key-val (LaTeX-listings-key-val-options)])
    '("ltx-code-result" LaTeX-env-args
      [TeX-arg-key-val (LaTeX-listings-key-val-options)])
    '("ltx-code-external-result" LaTeX-env-args
      [TeX-arg-key-val (LaTeX-listings-key-val-options)]
      TeX-arg-file))

   (add-to-list 'LaTeX-verbatim-environments-local "ltx-code")
   (add-to-list 'LaTeX-verbatim-environments-local "ltx-code-result")
   (add-to-list 'LaTeX-verbatim-environments-local "ltx-code-external-result")

   ;; Fontification
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("title"    "[{")
                                ("subtitle" "[{")
                                ("item"     "*["))
                              'textual)
     (font-latex-add-keywords '(("letgutsetup"    "{"))
                              'function)
     ;; Sectioning keywords
     (font-latex-add-keywords '(("title" "[{"))
                              'sectioning-1)
     (font-latex-add-keywords '(("subtitle" "[{"))
                              'sectioning-2)))
 TeX-dialect)

(defvar LaTeX-letgut-class-options
  '("for-readers" "for-authors")
  "Options for the letgut document class.")
