0

I am trying to make a tcolorboxenvironment. Without the package tcolorbox, I want to have an environment that acts the same way as declarenewentry:

\newcommand{\declarenewentry}[1]{\medskip\noindent\framebox[\textwidth][l]{\qquad #1}\medskip}

This will be my question:

Is there an environment that acts the same way as framebox?

6
  • Should category code changes work inside your environment (should there be any verbatim content)? And should the environment allow automatic linebreaks or behave really just like \framebox?
    – Skillmon
    Commented Jul 2, 2021 at 7:42
  • Yes, just like \framebox, though I am not sure about the category code since I have no idea about that.
    – soupless
    Commented Jul 2, 2021 at 7:45
  • Boils down to: Do you want to use \verb|<stuff>| inside the environment or not?
    – Skillmon
    Commented Jul 2, 2021 at 7:49
  • No, there should be no verbatim content.
    – soupless
    Commented Jul 2, 2021 at 7:52
  • You can also use the environ package and \fbox{\BODY}. Of course, the entire text will be implemented as a single line. Commented Jul 2, 2021 at 14:24

1 Answer 1

3

The following shows two different approaches how you could collect the contents of the environment. The first one (declarenewenryENV) uses lrbox to collect stuff inside a box, and then inserts the box contents into your \framebox (I just called \declarenewentry inside the environment for convenience).

The second approach (otherENV) collects the environment body as an argument. That approach is much simpler to code, but doesn't allow verbatim material (so no \verb) inside the document body.

Overall the second approach should be preferred, imho, if support for \verb isn't necessary.

\documentclass[]{article}

\newsavebox\declarenewentryBOX
\newenvironment{declarenewentryENV}
  {\begin{lrbox}\declarenewentryBOX}
  {%
    \end{lrbox}%
    \declarenewentry{\unhbox\declarenewentryBOX}%
  }
\newcommand{\declarenewentry}[1]
  {\medskip\noindent\framebox[\textwidth][l]{\qquad #1}\medskip}

\NewDocumentEnvironment{otherENV}{b}
  {}
  {\declarenewentry{#1}}

\usepackage{duckuments}

\begin{document}
\blindduck
\declarenewentry{abc is def}
\blindduck
\begin{declarenewentryENV}
  abc is def
\end{declarenewentryENV}
\blindduck
\begin{otherENV}
  abc is def
\end{otherENV}
\end{document}

All three calls (macro, environment collecting a box, environment collecting the body as an argument) show the exact same behaviour in the small test document shown above (you should probably add a \par before \medskip in your \declarenewentry macro).

Result:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .