(* ::Package:: *)

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

(* ::Input::Initialization:: *)
SetOptions[$FrontEndSession,PrintingStyleEnvironment->"Working"];
nb2tex[nb_String,opts___Rule]:=nb2tex[nb,nb,opts];


(* ::Input::Initialization:: *)
nb2tex[nb_String,tex_String, opts___Rule]:=Module[
{notebook,PDFCounter=0,type,tag,pdfname,cells,cell,c,cl,texfiles={},TeXOut,
PDFFolder=PDFFolder/. {opts}/.PDFFolder->nb
},
nb2tex$TeXFileName=tex<>".tex";
nb2tex$PDFWidth = PDFWidth /. {opts} /. PDFWidth->6.5;
TeXOut[s_String]:=(texfiles=texfiles\[Union]{nb2tex$TeXFileName};
WriteString[nb2tex$TeXFileName,s]);
notebook=NotebookGet[NotebookOpen@FileNameJoin[{Directory[],nb<>".nb"}]];
If[FileType[PDFFolder]===None, CreateDirectory[PDFFolder]];
DeleteFile/@FileNames["*.pdf",PDFFolder];
cells=Cases[notebook,c_Cell /; Length[c]>=2,\[Infinity]];
Do[
type=cell[[2]];
tag=CellTags /. Cases[cell,_Rule] /. CellTags->"";
Which[
type=="Text"\[And]tag=="tex", TeXOut[
StringReplace[cell[[1]],{"\[CloseCurlyQuote]"->"'", "\[CloseCurlyDoubleQuote]"->"\""}]<>"\n\n"],
StringMatchQ[tag,"pdf:"~~___], (
pdfname=PDFFolder<>"/"<>StringDrop[tag,4]<>type<>".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];
),
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];
TeXOut[StringReplace[
"\\noindent\\nbpdfXXXType{pdfname}\n\n",
{"XXX"->StringDrop[tag,3], "Type"->type, "pdfname"->pdfname}
]]
),
type=="Input"\[And]tag=="exec", ToExpression[cell[[1]]],
True, Null
],
{cell,cells}
];
Close/@texfiles;
]
