Skip to main content

export - Some tutorials on formatting notebook for exporting to pdf


I love the way that Mathematica allows me to type in of formulas. It is really easy to type complicated expressions with shortcuts on the keyboard. It would be great if I could use Mathematica completely to publish my articles. The biggest reason I don't already do this is:


I can't find the proper tutorial for styling notebooks for PDF export. How is it possible to deal with page numbering, headers, footers, page breaks, or placing graphs in specific positions, instead of being limited to line by line text? Is this possible? I believe it is -- I'm fascinated with Mathematica's capabilities, but I don't yet have the skills to take advantage of all the features it offers.


If someone would write tutorial on styling notebooks, formatting, and exporting to PDF, I believe that it would be appreciated by many others. I have seen some texts where it's emphasized that they are written totally in Mathematica (and they are really styled well).


Thank you for any tips, ways of accomplishing these tasks and for sharing your experience.



Answer



You can adjust page size, page number style, headers, footers, etc from items under File -> Printing Settings menu. Or you can programmatically modify them by manipulating Notebook's options: PrintingCopies, PrintingStartingPageNumber, PrintingPageRange, PageHeaderLines, PageFooterLines, PrintingOptions.



Mathematica graphics


Mathematica graphics


Note: It seems "PaperSize" and "PrintingMargins" are calculated using a DPI value of 72, which I guess is not the DPI of the monitor but that of the default printer.


Graphics, more generally, nearly any Cell expression, can be used in header and footer. One way is copy the entire Cell:


Mathematica graphics


then paste into the Headers and Footers palette:


Mathematica graphics



A sample Notebook(Sorry I didn't find a convenient place to store large texts..):


notebookStr = Uncompress["1:eJztWI1u2zYQ7jvsBTgBA5LN9fRrWd1QoE3qNkOcBLbRYbCMmZYYm4hCGhKVJf\

Xyjnuk3ZGyLdlp063dMAwlAkvi/fB4P9+R+XomB8M/vnry5EwqNpPyarw6Ylk2tkYLRkZUErWgiiRUkBkjKpdpygTh\
BRFSAYkRJtIy52JOqEhJKZIFFXP8BNE2QR2CXrOGEpxIP0YFMratFrFG7FZZkxYxhh0cSZEwfgNK5CWhxSFZ0BvNL7\
VIi3CF6lH1ec5BFVUyR94FozdgPS7DaK4WP5CD5D266J6qvoRfrYZmGcwAV7Fv3Ut5e0wVHcfxwSinKVdcCpr1ZH4d\
x1OYxL9nruu+jONfaRx/M4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guMn/woc\
fyY0Rv/vouC2A7+lWalfrB7P2BlcV6wmfO60wve37t0u+kg3+diAV8eJnoSb5cPHiY1JJt7bHQ0XMgeWu2pXcUwe5O\
hDkS4Mj2ap0UEYJw9bu4Rf4OpnKCbAIzrH2ya+F1VIQVjhgWad/+ANs4nP2FsfC2O1YH3xKiNwkYcy48H4ntJCfczx\
7ASu9QraxuT9a+8U7/75b0cpefac9HKI0CuRTgdwgBWQXyyn2SMO/YvpZfL0lAtzEl71aFZUYN1IwC2HKXjNVztMny\
/RaMNhQR+uTsqFhTNGBCKUG3din9aEU3apGgSzrYdkqoKqkfp0LvglT7AZCU1w2roUlyw/zzlEZEuxLiDfc8oR5gwH\
gpImreCYAqeE2oDLhe+0I/ceeXF/6OSXOU2umGpsSBP7Zab4MmNvZM7fQbxotrdxzTdgc6iOXNsEEbva5wCfVaE0hq\

18OOnAMasb+JVlcO9xwLTQc91ugNHtBm3bi7zQrtm+O3WPsV6n0lvAEswu9Em3bWt87/Mkl4W8VNV1qiAHHf/pjKtD\
cnCeKImXoA4cu2zHOVwj4TG75IJvYr7z7y/DsimrHWYLvil4rS1mUCVg3FtecDgjIK3Kv3/YXKtqg5pWLBjTnZMqDI\
Gx6k/bOjzu"];

nbcontent = notebookStr // ToExpression // InputForm;

Define a function for display the headers and footers setting:


Clear[HeaderFooterSettingView]
HeaderFooterSettingView[nbcontent_] :=
Function[hf,

Cases[nbcontent, (hf -> expr_) :> expr, \[Infinity]] //
If[# === {},
{{None, None, None}, {None, None, None}},
#[[1]]] & //
Column[{
Style[ToString[hf] <> " Settings:", 20],
Grid[Prepend[
Map[If[# === None,
Item[Spacer[20], Background -> LightBlue],
Style[InputForm@#, 8]] &, #, {2}]\[Transpose],

Item[#, Background -> LightYellow] & /@
{"Right page", "Left Page"}
]\[Transpose],
Dividers -> {
{False, Black, GrayLevel[.8], GrayLevel[.8]},
2 -> Directive[Black, Thick]}]
}] &] /@ {PageHeaders, PageFooters} //
Column[#, Frame -> All, FrameStyle -> GrayLevel[.8]] &

HeaderFooterSettingView@nbcontent


enter image description here


Here the light-blue cells indicate empty slots for headers/footers.


Now we insert a Graphics at the right corner footer of right pages:


nbcontentNew = nbcontent /.
(PageFooters -> expr_) :>
(PageFooters -> ReplacePart[expr,
{1, 3} ->
Cell[BoxData[ToBoxes[
Graphics[{Circle[], Inset[x^2 + y^2 == r^2, {0, 0}]},

Frame -> True, ImageSize -> 100]
]]]
]);

nbNew = nbcontentNew[[1]] // NotebookPut

NotebookPrint gave a terrible result on my computer, so I manually selected the virtual pdf printer from Print dialog in the File menu to print the generated Notebook:


enter image description here


Comments

Popular posts from this blog

mathematical optimization - Minimizing using indices, error: Part::pkspec1: The expression cannot be used as a part specification

I want to use Minimize where the variables to minimize are indices pointing into an array. Here a MWE that hopefully shows what my problem is. vars = u@# & /@ Range[3]; cons = Flatten@ { Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; Minimize[{Total@((vec1[[#]] - vec2[[u[#]]])^2 & /@ Range[1, 3]), cons}, vars, Integers] The error I get: Part::pkspec1: The expression u[1] cannot be used as a part specification. >> Answer Ok, it seems that one can get around Mathematica trying to evaluate vec2[[u[1]]] too early by using the function Indexed[vec2,u[1]] . The working MWE would then look like the following: vars = u@# & /@ Range[3]; cons = Flatten@{ Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; NMinimize[ {Total@((vec1[[#]] - Indexed[vec2, u[#]])^2 & /@ R...

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

What is and isn't a valid variable specification for Manipulate?

I have an expression whose terms have arguments (representing subscripts), like this: myExpr = A[0] + V[1,T] I would like to put it inside a Manipulate to see its value as I move around the parameters. (The goal is eventually to plot it wrt one of the variables inside.) However, Mathematica complains when I set V[1,T] as a manipulated variable: Manipulate[Evaluate[myExpr], {A[0], 0, 1}, {V[1, T], 0, 1}] (*Manipulate::vsform: Manipulate argument {V[1,T],0,1} does not have the correct form for a variable specification. >> *) As a workaround, if I get rid of the symbol T inside the argument, it works fine: Manipulate[ Evaluate[myExpr /. T -> 15], {A[0], 0, 1}, {V[1, 15], 0, 1}] Why this behavior? Can anyone point me to the documentation that says what counts as a valid variable? And is there a way to get Manpiulate to accept an expression with a symbolic argument as a variable? Investigations I've done so far: I tried using variableQ from this answer , but it says V[1...