Clear

SetDirectory["C:\\drorbn\\AcademicPensieve\\Talks\\CMS-2112"];
DeleteFile/@{"BedAndKas.tex", "Verification.tex", "RunThrough.tex", "SideBySideNB.tex"};

Run

SetDirectory["C:\\drorbn\\AcademicPensieve\\Talks\\CMS-2112"];

$PageWidth=1.23N[284/72];

Make["BedAndKas.tex","BedAndKas.nb",Hold[nb2tex["BedAndKas", "BedAndKas", PDFFolder->"Snips/BedAndKas", PDFWidth->$PageWidth]]];

$PageWidth=0.9*154.3/10/2.54;

Make["Verification.tex","Verification.nb",Hold[nb2tex["Verification", "Verification", PDFFolder->"Snips/Verification", PDFWidth->$PageWidth]]];

Make["RunThrough.tex","RunThrough.nb",Hold[nb2tex["RunThrough", "RunThrough", PDFFolder->"Snips/RunThrough", PDFWidth->$PageWidth]]];

Make["KSC.pdf", {"KSC.tex", "BedAndKas.tex", "Verification.tex", "RunThrough.tex"},
Hold[Run@"\"C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\pdflatex.exe\" KSC.tex"
]]

$PageWidth=1.1N[284/72];

Make["SideBySideNB.tex","SideBySide.nb",Hold[nb2tex["SideBySide", "SideBySideNB", PDFFolder->"Snips/SideBySide", PDFWidth->$PageWidth]]];

Make["SideBySide.pdf", {"SideBySide.tex", "SideBySideNB.tex"},
Hold[Run@"\"C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\pdflatex.exe\" SideBySide.tex"
]]

Make

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]
]
];

nb2tex

As in http://drorbn.net/AcademicPensieve/Projects/nb2tex/.

SetOptions[$FrontEndSession,PrintingStyleEnvironment->"Working"];
nb2tex[nb_String,opts___Rule]:=nb2tex[nb,nb,opts];

nb2tex[nb_String,tex_String, opts___Rule]:=Module[
{notebook,PDFCounter=0,lines,type,tag,pdfname,cell,c,cl,
PDFFolder=PDFFolder/. {opts}/.PDFFolder->nb
},
nb2tex$PDFWidth = PDFWidth /. {opts} /. PDFWidth->6.5;
notebook=NotebookGet[NotebookOpen@FileNameJoin[{Directory[],nb<>".nb"}]];
If[FileType[PDFFolder]===None, CreateDirectory[PDFFolder]];
DeleteFile/@FileNames["*.pdf",PDFFolder];
lines=Table[
type=cell[[2]];
tag=CellTags /. Cases[cell,_Rule] /. CellTags->"";
Which[
type=="Text"∧tag=="tex", StringReplace[cell[[1]],{"’"->"'", "”"->"\""}],
StringMatchQ[tag,"pdf"~~___], (
pdfname=PDFFolder<>"/"<>ToString[++PDFCounter]<>".pdf";
Export[pdfname, Join[cell, Cell[PageWidth -> 80nb2tex$PDFWidth/0.75]]];
cl="c:\\drorbn\\bin\\cpdf.exe -scale-page \"0.75 0.75\" "<>pdfname<>" -o "<>pdfname;
Close@OpenRead["!"<>cl];
StringReplace[
"\\noindent\\nbpdfXXXType{pdfname}",
{"XXX"->StringDrop[tag,3], "Type"->type, "pdfname"->pdfname}
]
),
type=="Text"∧tag=="exec", ToExpression[cell[[1]]]; "",
True, ""
],
{cell,Cases[notebook,c_Cell /; Length[c]≥2(*∧FreeQ[c, _Cell, {1,∞}]*),∞]}
];
lines=StringJoin@@Riffle[DeleteCases[lines, ""], "\n\n"];
WriteString[tex<>".tex",lines]; Close[tex<>".tex"]; ]