(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



(* ::Input::Initialization:: *)
Make::usage = "Make[targets, sources, Hold[action]] makes a target, or a list of targets, given sources, or a list of sources, in the style of the unix 'make' command.";
Make[target_String, sources_, action_Hold] := Make[Evaluate@{target}, sources, action];
Make[targets_, source_String, action__Hold] := Make[targets, Evaluate@{source}, action];
Make[targets_List, sources_List, action_Hold] := Module[{},
If[
(And @@ ((FileType[#] =!= None)& /@ sources)) &&
Or[
Or @@ ((FileType[#]===None)& /@ targets),
Min[AbsoluteTime[FileDate[#]]& /@ targets] < Max[AbsoluteTime[FileDate[#]]& /@ sources]
],
Print["Making ",targets, " ..."];
ReleaseHold[action]
]
];


(* ::Input::Initialization:: *)
TeX2HTML[s_String] := StringReplace[s, {
"\\href{"~~u___~~"}{"~~l___~~"}" :> "<a href="<>u<>">"<>l<>"</a>",
(* LaTeX from http://stackoverflow.com/questions/8160514/is-there-css-for-typesetting-the-latex-logo-in-html *)
"\\LaTeX"->"L<sup style=\\\"text-transform: uppercase; font-size: 0.85em; vertical-align: 0.15em; margin-left: -0.36em; margin-right: -0.15em;\\\">a</sup>T<sub style=\\\"text-transform: uppercase; vertical-align: -0.5ex; margin-left: -0.1667em; margin-right: -0.125em; font-size: 1em;\\\">e</sub>X",
 "\\\"a" -> "&auml;", "\\\"o" -> "&ouml;", "\\\"u" -> "&uuml;", "``" -> "\\\"", "''" -> "\\\"", "\\ "->" ", "\\"->"\\\\"
}];
If[FileType["Confessions.js"]===None || (
FileType["Confessions.js"] === File && OrderedQ[{FileDate["Confessions.js"], FileDate["Confessions.tex"]}]),
Print["Projects/Agenda: Making Confessions.js ..."];
cs = TeX2HTML /@ StringCases[
Import["Confessions.tex", "text"],
Shortest["\\conf{"~~c___~~"\\fnoc}"] :> c
];
If[FileType["Confessions.js"]=!=None, DeleteFile["Confessions.js"]];
WriteString["Confessions.js",
"var Confessions = [\n  \""<>StringJoin@@Riffle[cs, "\",\n  \""]<>"\"\n];"
];
Close["Confessions.js"];
];


(* ::Input::Initialization:: *)
dpi=200;
PageName[k_Integer] := StringPadLeft[ToString[k],2,"0"]<>".png";
Make[k_Integer, src_] := Make[{k}, src];
Make[{ks__Integer}, src_] := Make[
Thread[Rule[Range[Length[{ks}]], {ks}]],
src
];
Make[pr_Rule, src_] := Make[{pr}, src]; (* pr: page rule *)
Make[prs_List, src_] :=  (* prs: page rules *)
Module[
{
f,t,ff,tt,
ds ,(* for dates changed *)
MT (* for Make Thumb *)
},
If[FileType[src] === File,
ds=Table[
tt="Projects/Agenda/"<>PageName[Last[pr]];
If[FileType[tt] === None, 0, AbsoluteTime[FileDate[tt]]
],
{pr,prs}
];
If[Min[ds]<AbsoluteTime[FileDate[src]],
Print["Projects/Agenda: Running Make[",prs, ", ", src, "]..."];
Read["!convert -scene 1 -density "<>ToString[dpi]<>" -background white -alpha remove \""<>src<>"\" Projects/Agenda/Temp.png"];
If[FileType["Projects/Agenda/Temp.png"] === File, 
RenameFile["Projects/Agenda/Temp.png", "Projects/Agenda/Temp-1.png"]
]
]
];
Cases[prs,  (f_->t_):>  (
ff="Projects/Agenda/Temp-"<>ToString[f]<>".png";
tt="Projects/Agenda/"<>PageName[t];
MT := (MakeThumb[PageName[t]]; MakePreview[PageName[t]]);
Which[
FileType[ff]===File &&  FileType[tt]===File, DeleteFile[tt]; RenameFile[ff,tt]; MT,
FileType[ff]===File && FileType[tt] === None, RenameFile[ff,tt]; MT,
FileType[ff] === None && FileType[tt] === None, (
Print["Projects/Agenda: Making an empty ",t,".png..."];
Export[tt, Rasterize[Image[{{1}}, ImageSize -> {8.5,11}dpi]]];
MT
)
]
)];
DeleteFile /@ FileNames["Projects/Agenda/Temp-*.png"]
];
Make["Agenda.png", K_Integer] := Module[{k, fk, ds,rows},
SetDirectory["Projects/Agenda"];
ds=Table[
fk=PageName[k];
If[FileType[fk] === None, 0, AbsoluteTime[FileDate[fk]]],
{k,K}
];
If[FileType["Agenda.png"]===None || Max[ds] > AbsoluteTime@FileDate["Agenda.png"],
rows=First@Ordering[Table[Abs[Log[9/16 (8.5 Ceiling[K/rows])/(11rows)]],{rows, K}]];
Print["Projects/Agenda: Making Agenda.png: "<>ToString[K]<>" pages in "<>ToString[rows]<>" rows..."];
Read[StringJoin[
"!montage -background white -geometry ",
ToString[8.5dpi]<>"x"<>ToString[11dpi],
"+0+0 -quality 90 -tile "<>ToString[Ceiling[K/rows]]<>" ",
StringJoin@@Table[PageName[k]<>" ", {k,K}],
"Agenda.png"
]];
MakeThumb@"Agenda.png"; MakePreview@"Agenda.png"
];

ResetDirectory[]
];


(* ::Input::Initialization:: *)
SetDirectory["C:\\drorbn\\AcademicPensieve"];
k=0;
Make[{++k,++k}, "Projects/Agenda/Confessions.pdf"];
Make[++k, "Projects/WKO4/CheatSheetFreeLie.pdf"];
Make[1 -> ++k, "2013-11/DoubleTree/DoubleTree.pdf"];
Make[{++k,++k}, "Projects/MetaCalculi/MetaCalculi.pdf"];
Make[++k, "2015-09/Unitarity.pdf"];
Make[++k, "Projects/Agenda/CSQG.pdf"];
Make["Agenda.png", k];
ResetDirectory[];


(* ::Input::Initialization:: *)
dpi=200;
Make[{"Monoblog.png", "Monoblog.html"}, {"Monoblog.pdf", "Monoblog.txt"}, Hold[
Print["Projects/Agenda: Making Monoblog.png and Monoblog.html..."];
$MonoblogPages=Import["Monoblog.pdf", "PageCount"];
rows=First@Ordering[Table[
Abs[Log[9/16 (8.5Ceiling[$MonoblogPages/rows])/(11rows)]],
{rows, $MonoblogPages}
]];
cols=Ceiling[$MonoblogPages/rows];
DeleteFile[FileNames["scratch/M-*.png"]];
Read["!convert -scene 1 -density "<>ToString[dpi]<>" -background white -alpha remove Monoblog.pdf scratch/M-%02d.png"];
Read["!montage -geometry +0+0 -frame 0 -background white -tile "<>ToString[cols]<>"x"<>ToString[rows]<>" scratch/M-*.png Monoblog.png"];
DeleteFile[FileNames["scratch/M-*.png"]];
MakeThumb@"Monoblog.png"; MakePreview@"Monoblog.png";
es1 = Get["Monoblog.pos"]//Most;
es2 = es1 /. Entry[k_, id_, x_,y_] :> If[x<4.25,
Entry[2k-1, id, x, 11-y],
Entry[2k, id, x-4.25, 11-y]
];
es3 = Flatten[Table[
If[es2[[k,1]]!=es2[[k+1,1]] && es2[[k+1,4]] >0.42,
{
Entry[es2[[k,1]], es2[[k,2]]<>"-1", {0, es2[[k,4]]-0.1},{4.25,11}],
Entry[es2[[k,1]]+1, es2[[k,2]]<>"-2", {0, 0},{4.25,es2[[k+1,4]]+0.1}]
},
Entry[es2[[k,1]], es2[[k,2]], {0, es2[[k,4]]-0.1}, {4.25,If[es2[[k+1,4]]>es2[[k,4]], es2[[k+1,4]]+0.1, 11]}]
],
{k, Length[es2]-1}
]];
es4 = es3 /. Entry[k_, id_, {x1_,y1_}, {x2_,y2_}] :> Module[{sx,sy},
sx=4.25*Mod[k-1, 2cols]; sy=11*Quotient[k-1, 2cols];
Entry[id, {sx+x1,sy+y1}, {sx+x2,sy+y2}]
];
es5 = es4 /. Entry[id_, {x1_,y1_}, {x2_,y2_}] :> StringJoin["  [", ToString[x1], ",", ToString[y1], ",", ToString[x2], ",", ToString[y2], ",\"", id, "\"]"];
views=StringJoin@@Riffle[es5, ",\n"];
FileTemplateApply[FileTemplate["Monoblog.txt"], "Monoblog.html"];
Print["...Monoblog.html: ", 1+Length@es5, " views in ", rows, "x", cols, "."]
]]


(* ::Input::Initialization:: *)
{
"CleanTeX" -> True,
"TitleNotes" -> "This is the Pensieve home of <a href=Agenda.png>Agenda.png</a>, <a href=Confessions.pdf>Confessions.pdf</a>, <a href=Monoblog.pdf>Monoblog.pdf</a>, <a href=TDBID.pdf>TDBID.pdf</a>, and <a href=CSQG.pdf>CSQG.pdf</a>.<p>"
}
