src/Pure/Thy/html.ML
changeset 14571 b88d5f9e02e1
parent 14565 c6dc17aab88a
child 14598 7009f59711e3
equal deleted inserted replaced
14570:0bf4e84bf51d 14571:b88d5f9e02e1
    93      | "\\<threequarters>" => (1.0, "&frac34;")
    93      | "\\<threequarters>" => (1.0, "&frac34;")
    94      | "\\<questiondown>" => (1.0, "&iquest;")
    94      | "\\<questiondown>" => (1.0, "&iquest;")
    95      | "\\<times>" => (1.0, "&times;")
    95      | "\\<times>" => (1.0, "&times;")
    96      | "\\<emptyset>" => (1.0, "&Oslash;")
    96      | "\\<emptyset>" => (1.0, "&Oslash;")
    97      | "\\<div>" => (1.0, "&divide;")
    97      | "\\<div>" => (1.0, "&divide;")
    98      | "\\<circ>" => (1.0, "&circ;")    
    98      | "\\<circ>" => (1.0, "&circ;")
    99      | "\\<Alpha>" => (1.0, "&Alpha;")
    99      | "\\<Alpha>" => (1.0, "&Alpha;")
   100      | "\\<Beta>" => (1.0, "&Beta;")
   100      | "\\<Beta>" => (1.0, "&Beta;")
   101      | "\\<Gamma>" => (1.0, "&Gamma;")
   101      | "\\<Gamma>" => (1.0, "&Gamma;")
   102      | "\\<Delta>" => (1.0, "&Delta;")
   102      | "\\<Delta>" => (1.0, "&Delta;")
   103      | "\\<Epsilon>" => (1.0, "&Epsilon;")
   103      | "\\<Epsilon>" => (1.0, "&Epsilon;")
   160      | "\\<Sum>" => (1.0, "&sum;")
   160      | "\\<Sum>" => (1.0, "&sum;")
   161      | "\\<star>" => (1.0, "&lowast;")
   161      | "\\<star>" => (1.0, "&lowast;")
   162      | "\\<propto>" => (1.0, "&prop;")
   162      | "\\<propto>" => (1.0, "&prop;")
   163      | "\\<infinity>" => (1.0, "&infin;")
   163      | "\\<infinity>" => (1.0, "&infin;")
   164      | "\\<angle>" => (1.0, "&ang;")
   164      | "\\<angle>" => (1.0, "&ang;")
   165      | "\\<and>" => (1.0, "&and;")     
   165      | "\\<and>" => (1.0, "&and;")
   166      | "\\<or>" => (1.0, "&or;")
   166      | "\\<or>" => (1.0, "&or;")
   167      | "\\<inter>" => (1.0, "&cap;")
   167      | "\\<inter>" => (1.0, "&cap;")
   168      | "\\<union>" => (1.0, "&cup;")
   168      | "\\<union>" => (1.0, "&cup;")
   169      | "\\<sim>" => (1.0, "&sim;")
   169      | "\\<sim>" => (1.0, "&sim;")
   170      | "\\<cong>" => (1.0, "&cong;")
   170      | "\\<cong>" => (1.0, "&cong;")
   189      | "\\<lozenge>" => (1.0, "&loz;")
   189      | "\\<lozenge>" => (1.0, "&loz;")
   190      | "\\<spadesuit>" => (1.0, "&spades;")
   190      | "\\<spadesuit>" => (1.0, "&spades;")
   191      | "\\<clubsuit>" => (1.0, "&clubs;")
   191      | "\\<clubsuit>" => (1.0, "&clubs;")
   192      | "\\<heartsuit>" => (1.0, "&hearts;")
   192      | "\\<heartsuit>" => (1.0, "&hearts;")
   193      | "\\<diamondsuit>" => (1.0, "&diams;")
   193      | "\\<diamondsuit>" => (1.0, "&diams;")
   194 
       
   195      | "\\<lbrakk>" => (2.0, "[|")
   194      | "\\<lbrakk>" => (2.0, "[|")
   196      | "\\<rbrakk>" => (2.0, "|]")
   195      | "\\<rbrakk>" => (2.0, "|]")
   197      | "\\<Longrightarrow>" => (3.0, "==&gt;")
   196      | "\\<Longrightarrow>" => (3.0, "==&gt;")
   198      | "\\<Rightarrow>" => (3.0, "=&gt;")
   197      | "\\<Rightarrow>" => (2.0, "=&gt;")
   199      | "\\<And>" => (2.0, "!!")
   198      | "\\<And>" => (2.0, "!!")
   200      | "\\<Colon>" => (2.0, "::")
   199      | "\\<Colon>" => (2.0, "::")
   201      | "\\<lparr>" => (2.0, "(|")
   200      | "\\<lparr>" => (2.0, "(|")
   202      | "\\<rparr>" => (2.0, "|)")
   201      | "\\<rparr>" => (2.0, "|)")
   203      | "\\<longleftrightarrow>" => (3.0, "&lt;-&gt;")
   202      | "\\<longleftrightarrow>" => (3.0, "&lt;-&gt;")
   204      | "\\<longrightarrow>" => (3.0, "--&gt;")
   203      | "\\<longrightarrow>" => (3.0, "--&gt;")
   205      | "\\<rightarrow>" => (2.0, "-&gt;")
   204      | "\\<rightarrow>" => (2.0, "-&gt;")
   206      | "\\<rightleftharpoons>" => (2.0, "==")
       
   207      | "\\<rightharpoonup>" => (2.0, "=&gt;")
       
   208      | "\\<leftharpoondown>" => (2.0, "&lt;=")
       
   209 
       
   210      | "\\<^bsub>" => (0.0, "<sub>")
   205      | "\\<^bsub>" => (0.0, "<sub>")
   211      | "\\<^esub>" => (0.0, "</sub>")
   206      | "\\<^esub>" => (0.0, "</sub>")
   212      | "\\<^bsup>" => (0.0, "<sup>")
   207      | "\\<^bsup>" => (0.0, "<sup>")
   213      | "\\<^esup>" => (0.0, "</sup>")
   208      | "\\<^esup>" => (0.0, "</sup>")
   214 (* keep \<^sub> etc, so they are not destroyed by default case *)
   209      | "\\<^sub>" => (0.0, "\\<^sub>")
   215      | "\\<^sup>" => (0.0, "\\<^sup>")
   210      | "\\<^sup>" => (0.0, "\\<^sup>")
   216      | "\\<^sub>" => (0.0, "\\<^sub>")
   211      | "\\<^isub>" => (0.0, "\\<^isub>")
   217      | "\\<^isup>" => (0.0, "\\<^isup>")
   212      | "\\<^isup>" => (0.0, "\\<^isup>")
   218      | "\\<^isub>" => (0.0, "\\<^isub>")
       
   219      | s => (real (size s), implode (map escape (explode s)));
   213      | s => (real (size s), implode (map escape (explode s)));
   220 
   214 
   221   fun add_sym (width, (w: real, s)) = (width + w, s);
   215   fun add_sym (width, (w: real, s)) = (width + w, s);
   222 
   216 
   223   fun script (0, "\\<^sub>") = (1,"<sub>")
   217   fun script (0, "\\<^sub>") = (1, "<sub>")
   224     | script (0, "\\<^isub>") = (1,"<sub>")
   218     | script (0, "\\<^isub>") = (1, "<sub>")
   225     | script (1, x) = (0, x ^ "</sub>")
   219     | script (1, x) = (0, x ^ "</sub>")
   226     | script (0, "\\<^sup>") = (2,"<sup>")
   220     | script (0, "\\<^sup>") = (2, "<sup>")
   227     | script (0, "\\<^isup>") = (2,"<sup>")
   221     | script (0, "\\<^isup>") = (2, "<sup>")
   228     | script (2, x) = (0, x ^ "</sup>")
   222     | script (2, x) = (0, x ^ "</sup>")
   229     | script (s, x) = (s,x);
   223     | script (s, x) = (s, x);
   230 
   224 
   231   fun scrs (s, []) = (s,[])
   225   fun scripts ss = #2 (foldl_map script (0, ss));
   232     | scrs (s, x::xs) = let val (s', x') = script (s, x)
       
   233                             val (s'', xs') = scrs (s', xs)
       
   234                         in (s'', x'::xs') end;
       
   235                            
       
   236   fun scripts ss = #2 (scrs (0,ss));
       
   237 in
   226 in
   238 
   227 
   239 fun output_width str =
   228 fun output_width str =
   240   if not (exists_string (equal "<" orf equal ">" orf equal "&") str) then (str, real (size str))
   229   if not (exists_string (equal "<" orf equal ">" orf equal "&") str)
       
   230   then (str, real (size str))
   241   else
   231   else
   242     let val (width, syms) = foldl_map add_sym (0.0, map output_sym (Symbol.explode str))
   232     let val (width, syms) = foldl_map add_sym (0.0, map output_sym (Symbol.explode str))
   243     in (implode (scripts syms), width) end;
   233     in (implode (scripts syms), width) end;
   244 
   234 
   245 val output = #1 o output_width;
   235 val output = #1 o output_width;
   246 val output_symbols = scripts o (map (#2 o output_sym))
   236 val output_symbols = scripts o map (#2 o output_sym);
   247 
   237 
   248 end;
   238 end;
   249 
   239 
   250 
   240 
   251 val _ = Symbol.add_mode htmlN (output_width, Symbol.default_indent);
   241 val _ = Symbol.add_mode htmlN (output_width, Symbol.default_indent);
   367       "</ul>\n</div>\n<hr>\n<div class=\"sessions\">\n<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>";
   357       "</ul>\n</div>\n<hr>\n<div class=\"sessions\">\n<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>";
   368 
   358 
   369 
   359 
   370 (* theory *)
   360 (* theory *)
   371 
   361 
   372 fun verbatim_source ss = "\n</div>\n<hr>\n<div class=\"source\">\n<pre>" ^ 
   362 fun verbatim_source ss =
   373                          implode (output_symbols ss)  ^ 
   363   "\n</div>\n<hr>\n<div class=\"source\">\n<pre>" ^
   374                          "</pre>\n</div>\n<hr>\n<div class=\"theorems\">\n";
   364   implode (output_symbols ss)  ^
       
   365   "</pre>\n</div>\n<hr>\n<div class=\"theorems\">\n";
   375 
   366 
   376 
   367 
   377 local
   368 local
   378   fun encl None = enclose "[" "]"
   369   fun encl None = enclose "[" "]"
   379     | encl (Some false) = enclose "(" ")"
   370     | encl (Some false) = enclose "(" ")"
   398 
   389 
   399 (* ML file *)
   390 (* ML file *)
   400 
   391 
   401 fun ml_file path str =
   392 fun ml_file path str =
   402   begin_document ("File " ^ Url.pack path) ^
   393   begin_document ("File " ^ Url.pack path) ^
   403   "\n</div>\n<hr><div class=\"mlsource\">\n" ^ 
   394   "\n</div>\n<hr><div class=\"mlsource\">\n" ^
   404   verbatim str ^ 
   395   verbatim str ^
   405   "\n</div>\n<hr>\n<div class=\"mlfooter\">\n" ^ 
   396   "\n</div>\n<hr>\n<div class=\"mlfooter\">\n" ^
   406   end_document;
   397   end_document;
   407 
   398 
   408 
   399 
   409 (* theorems *)
   400 (* theorems *)
   410 
   401