@@ -130,10 +130,17 @@ CreateObj[style_String,capstyle_String,tag_:Automatic,captionFirst_:False]:=Bloc
130130tagt = TagInput [style ,tag ];
131131c = NotebookFind [EvaluationNotebook [],tagt ,All ,CellTags ];
132132tmp = c === $Failed ;
133- If [tmp ,FrontEnd ` NotebookWrite [EvaluationNotebook [],
133+ If [tmp ,If [captionFirst ,FrontEnd ` NotebookWrite [EvaluationNotebook [],CellPrint [TextCell ["\[ Placeholder]" ,capstyle ,CellAutoOverwrite -> False ]
134+ ],All ,AutoScroll -> False ];
135+ FrontEnd ` NotebookWrite [EvaluationNotebook [],
134136CellPrint [Cell [BoxData [FormBox ["\[ Placeholder]" ,TraditionalForm ]],style ,CellAutoOverwrite -> False ,CellTags -> tagt ]
135- ],All ,AutoScroll -> False ]; FrontEnd ` NotebookWrite [EvaluationNotebook [],CellPrint [TextCell ["\[ Placeholder]" ,capstyle ,CellAutoOverwrite -> False ]
137+ ],All ,AutoScroll -> False ];
138+ ,FrontEnd ` NotebookWrite [EvaluationNotebook [],
139+ CellPrint [Cell [BoxData [FormBox ["\[ Placeholder]" ,TraditionalForm ]],style ,CellAutoOverwrite -> False ,CellTags -> tagt ]
140+ ],All ,AutoScroll -> False ];
141+ FrontEnd ` NotebookWrite [EvaluationNotebook [],CellPrint [TextCell ["\[ Placeholder]" ,capstyle ,CellAutoOverwrite -> False ]
136142],All ,AutoScroll -> False ]];
143+ ];
137144c = NotebookFind [EvaluationNotebook [],tagt ,All ,CellTags ];
138145tmp
139146];
@@ -146,17 +153,21 @@ Paste[EvaluationNotebook[],content];
146153SelectionMove [EvaluationNotebook [],Next ,Cell ,1 ,AutoScroll -> False ];
147154SelectionMove [EvaluationNotebook [],After ,CellContents ,1 ,AutoScroll -> False ];
148155];
149- (*Board[content_,tag_:Automatic,row_:True,opts___]:=Block[{createdNew},
150- createdNew=CreateObj["Board",If[tag===Automatic&&Head@Unevaluated@content===Symbol,SymbolName[Unevaluated[content]],tag],True];
151- SelectionMove[EvaluationNotebook[],After,CellContents,AutoScroll->False];
156+ Board [content_ ,tag_ :Automatic ,row_ :True ,opts___ ]:= Block [{createdNew },
157+ createdNew = CreateObj ["Table" ,"TableTitle" ,If [tag === Automatic && Head @ Unevaluated @ content === Symbol ,SymbolName [Unevaluated [content ]],tag ],True ];
158+ Paste [EvaluationNotebook [],TableForm [content ,opts ]];
159+ SelectionMove [EvaluationNotebook [],Previous ,Cell ,1 ,AutoScroll -> False ];
160+ SelectionMove [EvaluationNotebook [],Before ,CellContents ,1 ,AutoScroll -> False ];
161+ (*SelectionMove[EvaluationNotebook[],After,CellContents,AutoScroll->False];*)
162+ (*
152163SelectionMove[EvaluationNotebook[],Previous,Line,1,AutoScroll->False];
153164If[!createdNew,SelectionMove[EvaluationNotebook[],All,Expression,AutoScroll->False],Unevaluated[Sequence[]]];
154165NotebookWrite[EvaluationNotebook[],GridBox[content,opts,GridBoxAlignment->{"Columns"->{{Left}},"ColumnsIndexed"->{},"Rows"->{{Center}},"RowsIndexed"->{}},GridBoxDividers->{"Columns"->{False,If[!row,AbsoluteThickness[1],Nothing],{False},False},"ColumnsIndexed"->{},"Rows"->{AbsoluteThickness[2],If[row,AbsoluteThickness[1],Nothing],{False},AbsoluteThickness[2]},"RowsIndexed"->{}},GridBoxItemSize->{"Columns"->{{All}},"ColumnsIndexed"->{},"Rows"->{{1.2}},"RowsIndexed"->{}},GridDefaultElement:>"\[Placeholder]"]];
155- SelectionMove[EvaluationNotebook[],Previous,Expression,2,AutoScroll->False];
166+ SelectionMove[EvaluationNotebook[],Previous,Expression,2,AutoScroll->False];*)
156167];
157168ExtFT [cs_ ,cont_ ]:= If [cs === "Board" ,Replace [cont ,{FormBox [GridBox [{_ ,{C___ },{D___ }},E___ ],F___ ]:> FormBox [GridBox [{{C },{D }},E ],F ]},Infinity ],If [cs === "Figure" ,Replace [cont ,{FormBox [GridBox [{{C___ },_ ,{D___ }},E___ ],F___ ]:> FormBox [GridBox [{{C },{D }},E ],F ]},Infinity ],cont ]];
158169BoardColumn [content_ ,tag_ :Automatic ,opts___ ]:= Board [content ,tag ,False ,opts ];
159- *)
170+
160171
161172DuplicateNotebook []:= NotebookPut @ NotebookGet [EvaluationNotebook []];
162173TranslateSpecialCellStyleNames [name_ ]:= If [AbsoluteCurrentValue ["Language" ] == "Polish" ,Switch [name ,"Example" ,"Przyk\[ LSlash]ad" ,"Exercise" ,"Zadanie" ,"Solution" ,"Rozwi\: 0105zanie" ,"Question" ,"Pytanie" ,"Remark" ,"Uwaga" ,"Comment" ,"Komentarz" ,
@@ -356,7 +367,7 @@ ShowStatus["PDF exported successfully"];
356367
357368Options [ExportToTeX ]= {TeXExportToPDF -> False ,TeXEmbedRefrencesBeforeExport -> False ,TeXWriteTOC -> False ,TeXBibFile -> "" ,
358369TeXWriteAuthors -> False ,TeXWriteDate -> False ,TeXWriteTitle -> True ,TeXCustomCommands -> "" ,TeXLanguage -> None ,TeXLineSpread -> "1.0" ,
359- TeXShowLabels -> False ,TeXSetMargin -> "0.8in" ,TeXPlotScale -> "0.7" ,TeXFitEquations -> True ,TeXAlignEquations -> True };
370+ TeXShowLabels -> False ,TeXSetMargin -> "0.8in" ,TeXPlotScale -> "0.7" ,TeXFitEquations -> False ,TeXAlignEquations -> True };
360371ExportToTeX [opt :OptionsPattern []]:= Module [{cells ,base ,prolog ,epilog ,styles ,title , author , abstract , affil ,tmps },
361372ShowStatus ["Initializing TeX export..." ];
362373PrintToConsole ["TeXExportToPDF is " <> ToString [OptionValue [TeXExportToPDF ]]];
@@ -636,10 +647,18 @@ ShowStatus["Postprocessing cells..."];
636647(*fix figure captions*)
637648base = StringReplace [base ,"\\ label{" ~~ Shortest [t___ ]~~ "}\\ end{figure}" ~~ Whitespace ~~ "\\ caption{" ~~ Shortest [c___ ]~~ "}" /; (StringCount [c ,"\\ (" ]== StringCount [c ,"\\ )" ]&& StringCount [c ,"{" ]== StringCount [c ,"}" ]&& StringFreeQ [t ,"}" ](*&&(!StringContainsQ[c,"\\ref"]||((StringCount[c,"{"]==StringCount[c,"\\ref"])&&(StringCount[c,"}"]==StringCount[c,"\\ref"])))*)(*&&StringFreeQ[t,"}"]*) ) :> "\\ caption{ " <> c <> " }\\ label{" <> t <> "}\\ end{figure} " ];
638649(*alignment*)
639- PutAlignMark [st_ String ]:= If [Length [StringSplit [st ,"\\\\ " ]]> 1 ,(StringRiffle [(tmps = If [StringContainsQ [# ,"=" ],StringReplace [# ,StartOfString ~~ Shortest [t___ ]~~ "=" ~~ u___ ~~ EndOfString /; (StringCount [t ,"{" ]== StringCount [t ,"}" ]):> t <> "&=" <> u ],StringReplace [# ,StartOfString ~~ Shortest [t___ ]~~ Pattern [z ,Blank []]~~ u___ ~~ EndOfString /; ((z === "+" ||z === "-" )&& StringCount [t ,"{" ]== StringCount [t ,"}" ]) :> t <> "&" <> z <> u ]]; If [StringContainsQ [tmps ,"&" ],tmps ,"&" <> tmps ]) & /@ StringSplit [st ,"\\\\ " ],"\\\\\n " ]),st ];
650+ PutAlignMark [st_ String ]:= If [Length [StringSplit [st ,"\\\\ " ]]> 1 ,(StringRiffle [(tmps = If [StringContainsQ [# ,"=" ],StringReplace [# ,StartOfString ~~ Shortest [t___ ]~~ "=" ~~ u___ ~~ EndOfString /; (StringCount [t ,"{" ]== StringCount [t ,"}" ]):> t <> " &=" <> u ],StringReplace [# ,StartOfString ~~ Shortest [t___ ]~~ Pattern [z ,Blank []]~~ u___ ~~ EndOfString /; ((z === "+" ||z === "-" )&& StringCount [t ,"{" ]== StringCount [t ,"}" ]) :> t <> " &" <> z <> u ]]; If [StringContainsQ [tmps ,"&" ],tmps ," &" <> tmps ]) & /@ StringSplit [st ,"\\\\ " ],"\\\\\n " ]),st ];
640651base = StringReplace [base ,"\\\\ " ~~ Whitespace ~~ "\\ end{aligned}" -> "\\ end{aligned}" ];
641652base = StringReplace [base ,"\\ begin{aligned}" ~~ Shortest [t___ ]~~ "\\ end{aligned}" /; ! StringContainsQ [t ,"\\ begin{array}" ]:> "\\ begin{aligned}" <> PutAlignMark [t ]<> "\\ end{aligned} " ];
642653base = StringReplace [base ,"\\ begin{aligned}\\ begin{array}{l}" ~~ Shortest [t___ ]~~ "\\ end{array}\\ end{aligned}" /; ! StringContainsQ [t ,"\\ begin{array}" ]:> "\\ begin{aligned}" <> PutAlignMark [t ]<> "\\ end{aligned} " ];
654+ (*fix double superscript error connected with primed variables*)
655+ base = StringReplace [base ,"'^" ~~ t_ /; ! (StringContainsQ [t ,"{" ]):> ("^{\\ prime " <> t <> "}" )];
656+ base = StringReplace [base ,"'^{" ~~ Shortest [t___ ]~~ "}" /; StringCount [t ,"{" ]== StringCount [t ,"}" ]:> ("^{\\ prime " <> t <> "}" )];
657+ base = StringReplace [base ,"''^" ~~ t_ /; ! (StringContainsQ [t ,"{" ]):> ("^{\\ prime \\ prime " <> t <> "}" )];
658+ base = StringReplace [base ,"''^{" ~~ Shortest [t___ ]~~ "}" /; StringCount [t ,"{" ]== StringCount [t ,"}" ]:> ("^{\\ prime \\ prime " <> t <> "}" )];
659+
660+ base = StringReplace [base ,"'" ~~ Whitespace ~~ "^" ~~ t_ /; ! (StringContainsQ [t ,"{" ]):> ("^{\\ prime " <> t <> "}" )];
661+ base = StringReplace [base ,"'" ~~ Whitespace ~~ "^{" ~~ Shortest [t___ ]~~ "}" /; StringCount [t ,"{" ]== StringCount [t ,"}" ]:> ("^{\\ prime " <> t <> "}" )];
643662(*cleanup*)
644663base = StringReplace [base ,{"\\ end{equation*}" ~~ Whitespace ~~ "\\ begin{equation*}" -> "\\ end{equation*}\n\\ begin{equation*}" ,"\\ end{equation}" ~~ Whitespace ~~ "\\ begin{equation}" -> "\\ end{equation}\n\\ begin{equation}" ,"\\ end{equation}" ~~ Whitespace ~~ "\\ begin{equation*}" -> "\\ end{equation}\n\\ begin{equation*}" }];
645664(*remove spacing for glueing TeX ref*)
0 commit comments