Created
April 14, 2018 02:36
-
-
Save s-fubuki/d5a6d14fe0662f8c4fdbdee19f747fef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; cal-tex-color.el -- cal-tex-color for year calendar TeX for color. | |
;; Copyright (C) 2014, 2018 fubuki | |
;; Author: fubuki@*****.org | |
;; Keywords: tools | |
;; This program is free software: you can redistribute it and/or modify | |
;; it under the terms of the GNU General Public License as published by | |
;; the Free Software Foundation, either version 3 of the License. | |
;; This program is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
;; GNU General Public License for more details. | |
;; You should have received a copy of the GNU General Public License | |
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
;;; Commentary: | |
;; | |
;;; Installation: | |
;; (require 'cal-tex-color) | |
;;; Code: | |
(require 'calendar) | |
(require 'cal-tex) | |
(require 'holidays) | |
(defcustom cal-tex-color-mode 'color | |
"cal-tex-color color flag." | |
:type '(choice (const :tag "mono" mono) | |
(const :tag "color" color)) | |
:group 'calendar-tex) | |
(when (eq cal-tex-color-mode 'color) | |
(setq cal-tex-preamble-extra "\\usepackage[dvipdfmx]{graphicx,xcolor}")) | |
(defcustom cal-day-name-blackets | |
'((mono . ("(%s)" "%s" "%s" "%s" "%s" "%s" "%s")) | |
(color . ("{\\color{red}%s}" "%s" "%s" "%s" "%s" "%s" "{\\color{blue}%s}"))) | |
"cal-tex-color Day name Blackets." | |
:type '(list cons cons) | |
:group 'calendar-tex) | |
(defcustom cal-day-holiday-blackets | |
'((mono . "[%s]") | |
(color . "{\\color{red}%s}")) | |
"cal-tex-color Holiday name Blackets." | |
:type '(list cons cons) | |
:group 'calendar-tex) | |
(defcustom cal-tex-holiday-mark 'char | |
"cal-tex-color Holiday style. | |
nil : Legacy (Non Blackets) | |
digi : [digi] | |
char : [char]" | |
:type '(choice | |
(const :tag "Legacy" nil) | |
(const :tag "[digit]" digi) | |
(const :tag "[char]" char)) | |
:group 'calendar-tex) | |
(defcustom cal-tex-holiday-name-alias nil | |
"*cal-tex-minicalendar Holiday Short names alist. | |
'((\"み\" . \"緑\") (\"こ\" . \"子\") (\"敬\" . \"老\") (\"天\" . \"皇\"))" | |
:type '(repeat (cons string string)) | |
:group 'calendar-tex) | |
(defcustom holiday-length 1 | |
"*cal-tex short name length." | |
:type 'integer | |
:group 'calendar-tex) | |
;;; (defun holiday-char (holiday) | |
;;; (let* ((str (or (car holiday) "")) | |
;;; (key (ignore-errors (substring str 0 holiday-length))) | |
;;; (rep (assoc key cal-tex-holiday-name-alias))) | |
;;; (if rep (cdr rep) key))) | |
;; | |
;; cal-tex-mini-calendar for color | |
;; | |
(defun cal-tex-mini-calendar-wrap (month year name width height &optional ptsize colsep) | |
"Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT. | |
Optional string PTSIZE gives the point size (default \"scriptsize\"). | |
Optional string COLSEP gives the column separation (default \"1mm\"). | |
Edit: Holiday is \"(\"day\")\"." | |
(or colsep (setq colsep "1mm")) | |
(or ptsize (setq ptsize "scriptsize")) | |
(let* ((blank-days ; at start of month | |
(mod (- (calendar-day-of-week (list month 1 year)) | |
calendar-week-start-day) | |
7)) | |
(mode cal-tex-color-mode) | |
(name-blackets (cdr (assq mode cal-day-name-blackets))) | |
(holiday-blackets (cdr (assq mode cal-day-holiday-blackets))) | |
(last (calendar-last-day-of-month month year)) | |
(mark cal-tex-holiday-mark) | |
(len holiday-length) | |
(alias cal-tex-holiday-name-alias) | |
(str (concat "\\def\\" name "{\\hbox to" width "{%\n" | |
"\\vbox to" height "{%\n" | |
"\\vfil \\hbox to" width "{%\n" | |
"\\hfil\\" ptsize | |
"\\begin{tabular}" | |
(let ((align (if mark "c@" "r@"))) | |
(concat | |
"{@{\\hspace{0mm}}r@{\\hspace{" colsep | |
"}}" align "{\\hspace{" colsep "}}" align "{\\hspace{" colsep | |
"}}" align "{\\hspace{" colsep "}}" align "{\\hspace{" colsep | |
"}}" align "{\\hspace{" colsep "}}" align "{\\hspace{0mm}}}%\n")) | |
"\\multicolumn{7}{c}{" | |
(cal-tex-month-name month) | |
" " | |
(number-to-string year) | |
"}\\\\[1mm]\n"))) | |
(dotimes (i 7) | |
(setq str | |
(concat str | |
(format (nth (mod (+ calendar-week-start-day i) 7) | |
name-blackets) | |
(cal-tex-LaTeXify-string | |
(substring (aref calendar-day-name-array | |
(mod (+ calendar-week-start-day i) 7)) | |
0 2))) | |
(if (= i 6) | |
"\\\\[0.7mm]\n" | |
" & ")))) | |
(dotimes (_idummy blank-days) | |
(setq str (concat str " & "))) | |
(dotimes (i last) | |
(let ((hol (car (calendar-check-holidays (list month (1+ i) year))))) | |
(setq str (concat str | |
(cond ; LEVEL 1 | |
((and mark hol) ; if [holiday] | |
(format holiday-blackets | |
(cond ; LEVEL 2 | |
((eq mark 'digi) ;; [num] | |
(number-to-string (1+ i))) | |
((eq mark 'char) ;; [char] | |
(let* ((key (ignore-errors (substring hol 0 len))) | |
(rep (assoc key alias))) | |
(or (cdr rep) key)))))) | |
(mark ; if (sunday) | |
(format | |
(nth (mod (+ blank-days calendar-week-start-day i) 7) | |
name-blackets) | |
(number-to-string (1+ i)))) | |
(t | |
(number-to-string (1+ i))))) | |
str (concat str (if (zerop (mod (+ i 1 blank-days) 7)) | |
(if (= i (1- last)) | |
"" | |
"\\\\[0.5mm]\n") | |
" & "))))) | |
(setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n")) | |
str)) | |
(advice-add 'cal-tex-mini-calendar :override 'cal-tex-mini-calendar-wrap) | |
(provide 'cal-tex-color) | |
;; fin. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment