changeset 148:20a8da73ceb3 dev

merged
author HIROSE Yuuji <yuuji@koeki-u.ac.jp>
date Mon, 27 Sep 2010 17:08:44 +0900
parents 78803eda24b8 (current diff) f9d3c2451d19 (diff)
children 2008ee4c9c5d
files yatexprc.el
diffstat 8 files changed, 287 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/newpage.rb	Mon Sep 27 17:08:44 2010 +0900
@@ -0,0 +1,128 @@
+#!/usr/bin/env ruby
+# THIS is very very tentative.  Insufficient examination of function.
+# Create new HTML file referring other HTML file in the same directory.
+# (C)2010 by HIROSE Yuuji [yuuji@yatex.org]
+# Last modified Mon Sep  6 16:16:33 2010 on firestorm
+# $Id$
+# http://www.yatex.org
+# Example:
+#	newpage.rb		Create new index.html by copying template.
+#	newpage.rb foo.html	Create new foo.html whose by copying header
+#				and footer from index.html.
+#	newpage.rb d/sub.html	Create new directory d (if necessary) and
+#				d/sub.html by copying header/footer from
+#				index.html in a same directory or parent
+#				directory rewriting href to css file
+#				considering relative path.
+#	newpage.rb -o [file]	Forcibly overwrite existing file.
+#	newpage.rb -c cssfile	Set `cssfile' as defualt css.
+#	newpage.rb -t template	Set `template' as HTML template.
+require 'fileutils'
+
+mydir=File.dirname($0)
+myname=File.basename($0, ".rb")
+
+
+index = 'index.html'
+cssdefault = nil
+overwrite = nil
+template = __FILE__ #File.expand_path(myname+".html", mydir)
+
+def guesscss(dir)
+  
+end
+
+while ARGV[0] && /^-/ =~ (a0=ARGV[0].dup) && ARGV.shift
+  break if /^--$/ =~ a0
+  while /^-[A-Za-z]/ =~ a0
+    case a0
+    when "-c"                   # css
+      ARGV.shift; cssdefault = ARGV[0]
+    when "-t"                   # template
+      ARGV.shift; cssdefault = ARGV[0]
+    when "-o"                   # overwrite
+      overwrite = true
+    end
+    a0.sub!(/-.(.*)/, '-\\1')
+  end
+end
+
+outfile = ARGV[0]||index
+if !overwrite && test(?s, outfile) then
+  STDERR.printf("File \`%s' exists.  Use -o option to overwrite.\n", outfile)
+  exit 1
+end
+
+# set css default file
+dots = 0
+of = outfile
+dots+=1 while "." != (of=File.dirname(of))
+cssdir = "../"*dots
+
+# set copy source
+outdir = File.dirname(outfile)
+if "index.html" == File.basename(outfile)
+  src = (dots == 0 ? template : "index.html")
+elsif test(?s, outdir+"/index.html")
+  src = outdir+"/index.html"
+else
+  src = template
+end
+
+FileUtils.mkdir_p(outdir)
+
+cssfile = cssdir+"main.css"
+name = File.basename(outfile, ".html")
+begin
+  open(outfile, "w") do |out|
+    #IO.foreach(src) do |line|
+    if src == __FILE__
+      input = DATA
+    else
+      input = open(src, "r")
+    end
+    begin
+      html = input.readlines.join
+      html.sub!(%r|^<h1.*<\/h1>|i, sprintf("<h1>%s</h1>\n", name))
+      if !html.gsub!("__CSSFILE__", cssfile)
+        html.gsub!(/href=(['\"])(.*\.css)\1/, 'href="'+cssdir+'\2"')
+      end
+      html.gsub!("__TITLE__", name)
+      out.print html
+    ensure
+      input.close
+    end
+  end
+  printf(<<_EOS_, outfile, name)
+<a href="%s">%s</a>
+_EOS_
+rescue
+  p $!
+  STDERR.printf(<<'_EOS_', outfile, outfile)
+Cannot output to [%s].  Do
+  chmod +w %s
+or
+  chmod +w .
+or change output directory.
+_EOS_
+  exit 1
+end
+
+__END__
+<html>
+<head>
+<title>__TITLE__</title>
+<style type="text/css">
+<!--
+/* Local CSS here */
+-->
+</style>
+<link rel="stylesheet" type="text/css" href="__CSSFILE__">
+</head>
+
+<body>
+<h1>__TITLE__</h1>
+
+<!--#include virtual="/~yuuji/signature.html"-->
+</body>
+</html>
--- a/yahtml.el	Mon Sep 27 17:05:03 2010 +0900
+++ b/yahtml.el	Mon Sep 27 17:08:44 2010 +0900
@@ -1,6 +1,6 @@
 ;;; -*- Emacs-Lisp -*-
 ;;; (c) 1994-2010 by HIROSE Yuuji [yuuji(@)yatex.org]
-;;; Last modified Fri Feb 12 21:30:03 2010 on firestorm
+;;; Last modified Mon Sep 13 08:09:46 2010 on firestorm
 ;;; $Id$
 
 (defconst yahtml-revision-number "1.74.2"
@@ -417,7 +417,7 @@
     ("DefinitionList" . "dl")
     ("Preformatted" . "pre")
     ("table") ("thead") ("tbody") ("tfoot") ("tr") ("th") ("td")
-    ("address") 
+    ("address") ("button")
     ("h1") ("h2") ("h3") ("h4") ("h5") ("h6")
     ;; ("p") ;This makes indentation screwed up!
     ("style") ("script") ("noscript") ("div") ("object") ("ins") ("del")
@@ -880,6 +880,25 @@
 	"class(or class list delimited by \\[quoted-insert] SPC): "))
      nil YaTeX-minibuffer-completion-map nil)))
   
+(defvar yahtml-newpage-command "newpage.rb"
+  "*Command name to create new HTML file referring to index.html.
+This command should create new HTML file named argument 1 and
+output string like `<a href=\"newfile.html\">anchor tag</a>'.
+This program should take -o option to overwrite existing HTML file.")
+(defun yahtml-newpage (file ov)
+  "Create newpage via newpage script"
+  (interactive
+   (list
+    (let (insert-default-directory)
+      (read-file-name "New webpage file name: " ""))
+    current-prefix-arg))
+  (if (and (file-exists-p file) (not ov))
+      (error "%s already exists.  Call this with universal argument to force overwrite." file))
+  (insert (substring
+	   (YaTeX-command-to-string
+	    (concat yahtml-newpage-command " " (if ov "-o ") file))
+	   0 -1)))
+
 ;;; ---------- Add-in ----------
 (defun yahtml-addin (form)
   "Check add-in function's existence and call it if exists."
@@ -888,6 +907,7 @@
       (and (setq a (yahtml-css-get-element-completion-alist form))
 	   (not (equal last-command-char ?\C-j))
 	   (memq yahtml-current-completion-type '(multiline inline))
+	   (not (string-match "#" form))
 	   (yahtml-make-optional-argument ;should be made generic?
 	    "class" (yahtml-read-css a)))
       (if (and (intern-soft addin) (fboundp (intern-soft addin))
@@ -1116,6 +1136,10 @@
      ((eq alist 'file)
       (let ((insert-default-directory))
 	(read-file-name prompt "" default nil "")))
+     ((eq alist 'command)
+      (if (fboundp 'read-shell-command)
+	  (read-shell-command prompt)
+	(read-string prompt)))
      ((and alist (symbolp alist))
       (completing-read prompt (symbol-value alist) nil nil default))
      (alist
@@ -1563,6 +1587,16 @@
   "Add-in function for abbr."
   (yahtml-make-optional-argument "title" (yahtml-read-parameter "title")))
 
+(defun yahtml:button ()
+  (concat
+   (yahtml-make-optional-argument
+    "name" (yahtml-read-parameter "name"))
+   (yahtml-make-optional-argument
+    "type" (yahtml-read-parameter
+	    "type" "button" '(("submit")("reset")("button"))))
+   (yahtml-make-optional-argument
+    "value" (yahtml-read-parameter "value"))))
+
 ;;; ---------- Simple tag ----------
 (defun yahtml-insert-tag (region-mode &optional tag)
   "Insert <TAG> </TAG> and put cursor inside of them."
@@ -1656,7 +1690,8 @@
     (format "%s=\"%s\"--" (if (string-match "/" file) "virtual" "file") file)))
 
 (defun yahtml:!--\#exec ()
-  (format "cmd=\"%s\"--" (yahtml-read-parameter "cmd" "" '(("cmd" . file)))))
+  (format "cmd=\"%s\"--"
+	  (yahtml-read-parameter "cmd" "" '(("cmd" . command)))))
 
 ;;; ---------- Jump ----------
 (defun yahtml-on-href-p ()
@@ -2247,6 +2282,39 @@
 	(goto-char (get 'YaTeX-inner-environment 'point))))
     e))
 
+(defun yahtml-untranslate-string (str)
+  "Untranslate entity reference."
+  (let ((md (match-data)) (left "") (right str) b0 ch
+	(ct (append yahtml-entity-reference-chars-alist
+		    yahtml-entity-reference-chars-alist-default))
+	(revrex yahtml-entity-reference-chars-reverse-regexp))
+    (unwind-protect
+	(progn
+	  (while (string< "" right)
+	    (cond
+	     ((string-match revrex right)
+	      (setq ch (YaTeX-rassoc
+			(substring right (match-beginning 1) (match-end 1)))
+		    b0 (substring right 0 (match-beginning 0))
+		    right (substring right (match-end 0))
+		    left (concat left
+				 (substring right 0 (match-beginning 0))
+				 (char-to-string ch))))
+	     ((string-match "\\&#\\(x\\)?\\([0-9a-f]+\\);" right)
+	      (setq ch (substring right (match-beginning 2) (match-end 2))
+		    b0 (substring right 0 (match-beginning 0))
+		    right (substring right (match-end 0))
+		    left (concat left
+				 b0
+				 (char-to-string
+				  (if (match-beginning 1)
+				      (YaTeX-hex ch)
+				    (string-to-number ch))))))
+	     (t (setq left (concat left right)
+		      right ""))))
+	  left)
+      (store-match-data md))))
+
 ;;; ---------- filling ----------
 (defvar yahtml-saved-move-to-column (symbol-function 'move-to-column))
 (defun yahtml-move-to-column (col &optional force)
@@ -2453,9 +2521,9 @@
 ;;; ---------- Lint and Browsing ----------
 ;;; 
 (defun yahtml-browse-menu ()
-  "Browsing menu"
+  "Browsing or other external process invokation menu."
   (interactive)
-  (message "J)weblint p)Browse R)eload...")
+  (message "J)weblint p)Browse R)eload N)ewpage...")
   (let ((c (char-to-string (read-char))))
     (cond
      ((string-match "j" c)
@@ -2463,7 +2531,9 @@
      ((string-match "[bp]" c)
       (yahtml-browse-current-file))
      ((string-match "r" c)
-      (yahtml-browse-reload)))))
+      (yahtml-browse-reload))
+     ((string-match "n" c)
+      (call-interactively 'yahtml-newpage)))))
 
 (if (fboundp 'wrap-function-to-control-ime)
     (wrap-function-to-control-ime 'yahtml-browse-menu t nil))
@@ -2476,10 +2546,12 @@
   (interactive "bCall lint on buffer: ")
   (setq buf (get-buffer buf))
   (YaTeX-save-buffers)
-  (YaTeX-typeset
-   (concat yahtml-lint-program " "
-	   (file-name-nondirectory (buffer-file-name buf)))
-   yahtml-lint-buffer  "lint" "lint"))
+  (let ((bcmd (YaTeX-get-builtin "lint")))
+    (and bcmd (setq bcmd (yahtml-untranslate-string bcmd)))
+    (YaTeX-typeset
+     (concat (or bcmd yahtml-lint-program)
+	     " " (file-name-nondirectory (buffer-file-name buf)))
+     yahtml-lint-buffer  "lint" "lint")))
 
 (defun yahtml-file-to-url (file)
   "Convert local unix file name to URL.
@@ -2685,7 +2757,7 @@
       (cond
        ((and (> cols 0)
 	     (memq (read-char) '(?d ?D))) ;Duplication mode
-	(setq line (YaTeX-buffer-substring (point) cp)))
+	(setq line (YaTeX-buffer-substring (point) (1- cp))))
        (t				;empty cells
 	(setq line "<tr>" i 0)
 	(if (> cols 0)
--- a/yatex.new	Mon Sep 27 17:05:03 2010 +0900
+++ b/yatex.new	Mon Sep 27 17:08:44 2010 +0900
@@ -5,6 +5,9 @@
 	[prefix] t e でポイント位置を含む環境か数式環境をタイプセット。
 	M-C-SPC で環境だけでなく数式環境もマークする。
 	[prefix] t d でタイプセッタ起動成功のあと dvipdfmx を起動。
+	=== yahtml ===
+	[prefix] t ブラウザメニューに「n:新規ページ作成」を追加(実験)。
+	[prefix] t j のlintコマンドを <!-- #lint CmdLine --> で指定可。
 
 1.74	=== yatex ===
 	YaTeX-kanji-code が 4 のときは UTF-8 とした。
--- a/yatexadd.el	Mon Sep 27 17:05:03 2010 +0900
+++ b/yatexadd.el	Mon Sep 27 17:08:44 2010 +0900
@@ -2,8 +2,8 @@
 ;;; YaTeX add-in functions.
 ;;; yatexadd.el rev.18
 ;;; (c)1991-2006 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Thu Oct 15 09:18:40 2009 on firestorm
-;;; $Id: yatexadd.el,v f14ec50103d0 2009/09/27 22:55:44 yuuji $
+;;; Last modified Thu Sep  9 09:08:19 2010 on firestorm
+;;; $Id$
 
 ;;;
 ;;Sample functions for LaTeX environment.
@@ -1665,7 +1665,7 @@
     ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
     ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
     ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
-  "Colors defined in $TEXMF/tex/plain/colordvi.tex")
+  "Colors defined in $TEXMF/tex/plain/dvips/colordvi.tex")
 
 (defvar YaTeX:latex2e-basic-color-alist
   '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
--- a/yatexlib.el	Mon Sep 27 17:05:03 2010 +0900
+++ b/yatexlib.el	Mon Sep 27 17:08:44 2010 +0900
@@ -2,7 +2,7 @@
 ;;; YaTeX and yahtml common libraries, general functions and definitions
 ;;; yatexlib.el
 ;;; (c)1994-2009 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Thu May 27 15:09:44 2010 on firestorm
+;;; Last modified Sat Sep 11 11:40:11 2010 on firestorm
 ;;; $Id$
 
 ;; General variables
@@ -822,6 +822,21 @@
   (win-switch-to-window 1 (- last-command-char win:base-key)))
 
 ;;;###autoload
+(defun YaTeX-command-to-string (cmd)
+  (if (fboundp 'shell-command-to-string)
+      (funcall 'shell-command-to-string cmd)
+    (let ((tbuf " *tmpout*"))
+      (if (get-buffer-create tbuf) (kill-buffer tbuf))
+      (let ((standard-output (get-buffer-create tbuf)))
+	(unwind-protect
+	    (save-excursion
+	      (call-process
+	       shell-file-name nil tbuf nil YaTeX-shell-command-option cmd)
+	      (set-buffer tbuf)
+	      (buffer-string))
+	  (kill-buffer tbuf))))))
+      
+;;;###autoload
 (defun YaTeX-reindent (col)
   "Remove current indentation and reindento to COL column."
   (save-excursion
@@ -1052,6 +1067,37 @@
 	 (get-file-buffer pf)
 	 (switch-to-buffer (get-file-buffer pf)))))
 
+(defun YaTeX-get-builtin (key)
+  "Read source built-in command of %# usage."
+  (catch 'builtin
+    (let ((bl (delq nil (list (current-buffer)
+			      (and YaTeX-parent-file
+				   (get-file-buffer YaTeX-parent-file)))))
+	  (leader (or (cdr-safe (assq major-mode
+				      '((yatex-mode . "%#")
+					(yahtml-mode . "<!-- #"))))
+		      "")))
+      (save-excursion
+	(while bl
+	  (set-buffer (car bl))
+	  (save-excursion
+	    (goto-char (point-min))
+	    (if (and (re-search-forward
+		      (concat "^" (regexp-quote (concat leader key))) nil t)
+		     (not (eolp)))
+		(throw 'builtin
+		       (YaTeX-buffer-substring
+			(progn
+			  (skip-chars-forward " \t" (point-end-of-line))
+			  (point))
+			(if (string< "" comment-end)
+			    (progn
+			      (search-forward
+			       comment-end (point-end-of-line) t)
+			      (match-beginning 0))
+			  (point-end-of-line))))))
+	  (setq bl (cdr bl)))))))
+
 ;;;VER2
 (defun YaTeX-insert-struc (what env)
   (cond
@@ -1073,6 +1119,24 @@
    ((fboundp 'truncate-string) (truncate-string str width))
    (t (substring str 0 width))))
 
+(defun YaTeX-hex (str)
+  "Return int expressed by hexadecimal string STR."
+  (if (string< "20" emacs-version)
+      (string-to-number str 16)
+    (let ((md (match-data)))
+      (unwind-protect
+	  (if (string-match "[^0-9a-f]" str)
+	      (error "Non hexadecimal character in %s" str)
+	    (let ((i 0) d)
+	      (setq str (downcase str))
+	      (while (string< "" str)
+		(setq d (+ 0 (string-to-char str)) ; + 0 for XEmacs
+		      i (+ (* 16 i) (- d (if (<= d ?9) ?0 (- ?a 10))))
+		      str (substring str 1)))
+	      i))
+	(store-match-data md)))))
+
+
 ;;; Function for menu support
 (defun YaTeX-define-menu (keymap bindlist)
   "Define KEYMAP(symbol)'s menu-bindings according to BINDLIST.
--- a/yatexmth.el	Mon Sep 27 17:05:03 2010 +0900
+++ b/yatexmth.el	Mon Sep 27 17:08:44 2010 +0900
@@ -2,7 +2,7 @@
 ;;; YaTeX math-mode-specific functions.
 ;;; yatexmth.el
 ;;; (c)1993-2010 by HIROSE Yuuji [yuuji@yatex.org]
-;;; Last modified Fri May 28 15:21:26 2010 on firestorm
+;;; Last modified Sat Sep 11 15:51:37 2010 on firestorm
 ;;; $Id$
 
 ;;; [Customization guide]
@@ -175,6 +175,7 @@
    ("=<"	"leqq"		("<\n="		"≦"))
    (">"		"geq"		(">\n-"		">\n-"))
    (">="	"geqq"		(">\n="		"≧"))
+   ("=:"	"fallingdotseq"	(".\n==\n ."	"≒"))
    ("-="	"equiv"		("=\n-"		YaTeX-image-equiv))
    ("=-"	"equiv"		("=\n-"		YaTeX-image-equiv))
    ("---"	"equiv"		("=\n-"		YaTeX-image-equiv))
--- a/yatexpkg.el	Mon Sep 27 17:05:03 2010 +0900
+++ b/yatexpkg.el	Mon Sep 27 17:08:44 2010 +0900
@@ -2,7 +2,7 @@
 ;;; YaTeX package manager
 ;;; yatexpkg.el
 ;;; (c)2003-2010 by HIROSE, Yuuji [yuuji@yatex.org]
-;;; Last modified Fri May 28 15:16:04 2010 on firestorm
+;;; Last modified Sat Sep 11 15:50:40 2010 on firestorm
 ;;; $Id$
 
 (defvar YaTeX-package-ams-envs
@@ -32,6 +32,7 @@
     ("amsmath"	(env . YaTeX-package-ams-envs)
      		(section "tag" "tag*"))
     ("amssymb"	(maketitle "leqq" "geqq" "mathbb" "mathfrak"
+			   "fallingdotseq"
 			   "lll" "ggg")) ;very few.  Please tell us!
     ("graphicx" (section "includegraphics"
 			 "rotatebox" "scalebox" "resizebox" "reflectbox")
--- a/yatexprc.el	Mon Sep 27 17:05:03 2010 +0900
+++ b/yatexprc.el	Mon Sep 27 17:08:44 2010 +0900
@@ -2,7 +2,7 @@
 ;;; YaTeX process handler.
 ;;; yatexprc.el
 ;;; (c)1993-2010 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Mon Sep 27 17:03:24 2010 on duke
+;;; Last modified Mon Sep 27 17:07:41 2010 on duke
 ;;; $Id$
 
 ;(require 'yatex)
@@ -917,28 +917,6 @@
       (YaTeX-switch-to-buffer-other-window
        (concat (YaTeX-get-preview-file-name) ".tex"))))
 
-(defun YaTeX-get-builtin (key)
-  "Read source built-in command of %# usage."
-  (catch 'builtin
-    (let ((bl (delq nil (list (current-buffer)
-			      (and YaTeX-parent-file
-				   (get-file-buffer YaTeX-parent-file))))))
-      (save-excursion
-	(while bl
-	  (set-buffer (car bl))
-	  (save-excursion
-	    (goto-char (point-min))
-	    (if (and (re-search-forward
-		      (concat "^" (regexp-quote (concat "%#" key))) nil t)
-		     (not (eolp)))
-		(throw 'builtin
-		       (YaTeX-buffer-substring
-			(progn
-			  (skip-chars-forward " \t" (point-end-of-line))
-			  (point))
-			(point-end-of-line)))))
-	  (setq bl (cdr bl)))))))
-
 (defun YaTeX-save-buffers ()
   "Save buffers whose major-mode is equal to current major-mode."
   (basic-save-buffer)

yatex.org