Frame all the content

I am looking for the way of creating one border frame around everything I have.

Something like standalone class, but an outline insted of cropping. I would also like to manage margins, line thickness and its color.

Important to have the settings in the preambule, so I won't need to use, say \begin{tikzpicture}... for the framed content. It should frame everything automatically.

Here is how it should look like

\documentclass{article}

%%% Кւԍ⌡₭ϝძη₲₭⫳ძ⨍∈ηԌ <=== something code for the frame

\begin{document}
$$2+2=4$$
My beautiful text
\end{document}


• Hmm... really your document is one page (with a number in the bottom, a lot of blank space, etc.). How should the code know that you want only the text you marked? I mean, I think that the objective is not well defined. (Why not using a \fbox{\begin{minipage}... thing, or better, tcolorbox?) – Rmano May 26 '20 at 11:41
• Page numbering can be removed. It is also possible to use standalone class if it helps. – antshar May 26 '20 at 11:43
• Maybe you can add a \begin{rcolorbox} with \AtBeginDocument and the corresponding \end... at the end. Just to give a hint, no time now ;-) – Rmano May 26 '20 at 11:44
• There should not be anything related to the frame inside document environment – antshar May 26 '20 at 11:55

As suggest by @MadyYuvi use the framed package but apply it to the whole document.

% framedprob.tex  SE 546288

\documentclass{article}
\usepackage{framed}
\usepackage{lipsum}

\AtBeginDocument{\begin{framed}}
\AtEndDocument{\end{framed}}
\begin{document}
%\begin{framed}
$2+2=4$
My beautiful text.

\lipsum[1-7]
%\end{framed}

\end{document}


The framed package does enable you to change the width (and color?) of the framing lines but that requires delving into the package internals. Perhaps ask another question about this; Donald Arseneau, the creator of framed, is a contributor to SE.

• Thank you so much! What about lack of abilities to modify settings in framed package, I can simply use mdframed – antshar May 26 '20 at 17:56
• @antshar If mdframed works for you then use it. – Peter Wilson May 27 '20 at 17:54

I'm undeleting my answer just for the record. I didn't understand what you wanted but for sure tikz, tikzpagenodes and atbegshi packages will allow you to do what you want (and a lot of configuration is possible there).

Here is a sample code:

\documentclass{article}

\usepackage{xparse}
\usepackage{atbegshi}
\usepackage{tikz}
\usepackage{tikzpagenodes}

\NewDocumentCommand\StartFrame{}{
\begin{tikzpicture}[remember picture, overlay]
\draw (current page text area.north west) rectangle (current page text area.south east);
}

\NewDocumentCommand\EndFrame{}{
\end{tikzpicture}
}

\begin{document}

$2+2=4$
My beautiful text

\end{document}


If you want to limit your frame to the actual content, then tcolorbox may be a good choice and it is highly (and easily) customizable.

\documentclass{article}

\usepackage{xparse}
\usepackage{atbegshi}
\usepackage{tcolorbox}

\NewDocumentCommand\StartFrame{}{
\begin{tcolorbox}
}

\NewDocumentCommand\EndFrame{}{
\end{tcolorbox}
}

\AtBeginDocument{\StartFrame}
\AtEndDocument{\EndFrame}
\begin{document}

$2+2=4$
My beautiful text

\end{document}


I hope you don't mind me adding these options to the voted answer.

• I need a frame that would be only around the contend, not the whole page. – antshar May 26 '20 at 12:22
• Oops, sorry. I misunderstood. I remove my "answer". – Ivan May 26 '20 at 12:23
• I recall the first usage of AtBeginDocument from you. Edited answer is what I needed, great to find out about tcolorbox – antshar May 27 '20 at 13:58
• I discovered it a few days ago and I really like it. I'm glad it helped. – Ivan May 27 '20 at 20:20

If I understand your question correct manner, then simply try with the framed.sty package, and the MWE is:

\documentclass{article}
\usepackage{framed}

\begin{document}
\begin{framed}
$2+2=4$
My beautiful text
\end{framed}

\end{document}


Please correct me, if my understanding is wrong....

• The requester is asking for all configuration to be in and only in the preamble. – Ivan May 26 '20 at 13:09