5
$\begingroup$

I want to export a cell's input (the text of the command) as pdf/eps. I have used

Export["cell.pdf", cells[[1]]]

It works fine, however, I would like to change the width after which a line break appears. When exporting whole notebook as pdf, I can change margins of the page and the line breaks are performed accordingly, however, it does not affect this kind of export. This export does not seem to follow neither working nor printout styles.

Is there any way how to force a particular width of the exported pdf while having the same size of letters?

I tried ImageFormattingWidth as in this example of what I precisely want (but without Rasterize in pdf), it had no effect.

I am aware of partially duplicating this question which, however, have not been answered and do not include any examples.

I am using Mathematica 10.4.

An example of cells[[1]] is

Cell[BoxData[  RowBox[{RowBox[{"g", "=", 
  RowBox[{"{", 
    RowBox[{RowBox[{"{", 
        RowBox[{RowBox[{"1", "-", 
            FractionBox[
             RowBox[{RowBox[{"2", " ", "M", " ", "r"}], "-", 
               SuperscriptBox["Q", "2"]}], "\[Rho]2"]}], ",", 
          RowBox[{"-", "1"}], ",", "0", ",", 
          FractionBox[
           RowBox[{"a", " ", 
             RowBox[{"(", 
               RowBox[{RowBox[{"2", " ", "M", " ", "r"}], "-", 
                SuperscriptBox["Q", "2"]}], ")"}], " ", 
             SuperscriptBox[RowBox[{"Sin", "[", "\[Theta]", "]"}],
               "2"]}], "\[Rho]2"]}], "}"}], ",", 
      RowBox[{"{", 
        RowBox[{RowBox[{"-", "1"}], ",", "0", ",", "0", ",", 
          RowBox[{"a", " ", 
            SuperscriptBox[RowBox[{"Sin", "[", "\[Theta]", "]"}], 
             "2"]}]}], "}"}], ",", 
      RowBox[{"{", 
        RowBox[{"0", ",", "0", ",", RowBox[{"-", "\[Rho]2"}], ",",
           "0"}], "}"}], ",", 
      RowBox[{"{", 
        RowBox[{FractionBox[
           RowBox[{"a", " ", 
             RowBox[{"(", 
               RowBox[{RowBox[{"2", " ", "M", " ", "r"}], "-", 
                SuperscriptBox["Q", "2"]}], ")"}], " ", 
             SuperscriptBox[RowBox[{"Sin", "[", "\[Theta]", "]"}],
               "2"]}], "\[Rho]2"], ",", 
          RowBox[{"a", " ", 
            SuperscriptBox[RowBox[{"Sin", "[", "\[Theta]", "]"}], 
             "2"]}], ",", "0", ",", 
          RowBox[{"-", 
            FractionBox[
             RowBox[{"\[CapitalSigma]2", " ", 
               SuperscriptBox[
                RowBox[{"Sin", "[", "\[Theta]", "]"}], "2"]}], 
             "\[Rho]2"]}]}], "}"}]}], "}"}]}], ";"}]], "Input",  CellChangeTimes -> {{3.67481*10^9, 3.67481*10^9}}]
$\endgroup$

1 Answer 1

3
$\begingroup$

You can set the PageWidth option inside of the Cell's code. Assuming that a variable cell contains the raw Cell expression from your question, it is as simple as follows:

Export["cell.pdf", Append[cell, PageWidth -> 2000]]

If you have a CellObject, you can get the code of the Cell with NotebookRead and then proceed as above:

Export["cell.pdf", Append[NotebookRead@Cells[][[1]], PageWidth -> 2000]]

Here is how exported PDF looks when opened in Adobe Acrobat:

screenshot

$\endgroup$
1
  • $\begingroup$ Thank you very much! The info about Append was also useful :) $\endgroup$
    – fales
    Jun 14, 2016 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.