Skip to content

Instantly share code, notes, and snippets.

@isoraqathedh
Last active May 30, 2021 21:29
Show Gist options
  • Save isoraqathedh/172df0fc9b883af753a3f980bf2225ab to your computer and use it in GitHub Desktop.
Save isoraqathedh/172df0fc9b883af753a3f980bf2225ab to your computer and use it in GitHub Desktop.
The infobox environment and an example

infobox

This is a LaTeX package that allows authors to create informational boxes in a similar method to how wikis do it. It is written in a way such that org-mode users can use it without specifically requiring them to drop into LaTeX, i.e. things like plain lists, images and definition lists should work as expected and the environment can be exported to other backends such as HTML with less friction.

Example org-mode usage

#+Caption: This will become the title
#+Name: box:example
#+begin_infobox
Some text goes here. This will span the entire box.
In order to make better use of the available space and use two columns,
use the ~multicol~ package as here.

#+ATTR_LATEX: :options {2}
#+begin_multicols
\infoboxsection{Section 1}
- Key 1 :: Value 1
- Key 2 :: Value 2
- Key 3 :: Value 3

Actually there is no limit to what you can write here;
it's up to the author to structure the box as is appropriate.

\infoboxsection{Section 2}
| This          |   That |
|---------------+--------|
| Atomic number |      8 |
| Atomic mass   |     16 |
| Half-life     | Stable |
| Valence       |      2 |

\infoboxsection{Note on sections}
Infobox sections do not show up on table of contents
and are not in fact sections in the ~\section~ sense.
#+end_multicols
#+end_infobox

Example LaTeX usage

Keep in mind that this is actually generated by the org LaTeX generator, with minimal reformatting.

\begin{infobox}
  \caption{\label{box:example}This will become the title}
  Some text goes here. This will span the entire box.
  In order to make better use of the available space and use two columns,
  use the \texttt{multicol} package as here.

  \begin{multicols}{2}
    \infoboxsection{Section 1}
    \begin{description}
    \item[{Key 1}] Value 1
    \item[{Key 2}] Value 2
    \item[{Key 3}] Value 3
    \end{description}

    Actually there is no limit to what you can write here;
    it's up to the author to structure the box as is appropriate.

    \infoboxsection{Section 2}
    \begin{center}
      \begin{tabular}{lr}
        This & That\\
        \hline
        Atomic number & 8\\
        Atomic mass & 16\\
        Half-life & Stable\\
        Valence & 2\\
      \end{tabular}
    \end{center}

    \infoboxsection{Note on sections}
    Infobox sections do not show up on table of contents
    and are not in fact sections
    in the \texttt{\textbackslash{}section} sense.
  \end{multicols}
\end{infobox}

Result

\RequirePackage{newfloat}
\RequirePackage{caption}
\RequirePackage{adjustbox}
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{infobox}
[2021/03/28 v0.20210328 The infobox package]
\newcommand{\infoboxsection}[1]{%
\medskip
\colorbox{white}{\makebox[\columnwidth]{%
\large\bf#1%
}}%
}
\newcommand{\infoboxtitle@nofmt}[1]{%
\fcolorbox{black}{white}{\makebox[\columnwidth]{%
#1%
}}%
}
\newcommand{\infoboxtitle}[1]{%
\infoboxtitle@nofmt{%
\Large\bf#1%
}
}
\DeclareCaptionFormat{infoboxtitlecaption}{%
\infoboxtitle@nofmt{%
\makebox[\textwidth][c]{\Large\bf#3}% Centre: Title
\makebox[0pt][r]{#1#2}% Right side: box name and number,
% plus the separator (should be unused)
}
}
\DeclareFloatingEnvironment[
name=Box,
placement=htbp,
listname={List of Infoboxes}]{infobox}
\captionsetup[infobox]{
position=above,
format=infoboxtitlecaption,
labelsep=space
}
\newsavebox{\infobox@box}
\renewenvironment{infobox}{%
\@float{infobox}
\begin{lrbox}{\infobox@box}%
\begin{adjustbox}{padding=0ex 0ex 2ex 0ex}%
\begin{minipage}{0.95\textwidth}%
}{%
\end{minipage}%
\end{adjustbox}%
\end{lrbox}%
\fbox{\usebox{\infobox@box}}%
\end@float%
}
\renewenvironment{infobox*}{%
\@dblfloat{infobox}
\begin{adjustbox}{padding=0ex 0ex 2ex 0ex}%
\begin{minipage}{0.95\textwidth}%
\begin{adjustbox}{frame}
}{%
\end{adjustbox}
\end{minipage}%
\end{adjustbox}%
\end@dblfloat%
}
% Created 2021-03-28 Sun 23:00
% Intended LaTeX compiler: lualatex
\documentclass[11pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage[hidelinks]{hyperref}
\usepackage{fontspec}
\setmainfont{CMU Serif}
\usepackage{infobox}
\usepackage{multicol}
\author{isoraqathedh}
\date{2021-03-28}
\title{infobox}
\hypersetup{
pdfauthor={isoraqathedh},
pdftitle={infobox},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 27.1 (Org mode 9.4.4)},
pdflang={English}}
\begin{document}
\maketitle
This is a \LaTeX{} package that allows authors to create informational boxes
in a similar method to how wikis do it.
It is written in a way such that \texttt{org-mode} users can use it
without specifically requiring them to drop into \LaTeX{},
i.e. things like plain lists, images and definition lists
should work as expected
and the entire can be exported to other backends such as HTML
with only a minimal change in CSS.
\section{Example org-mode usage}
\label{sec:org071b6bb}
\begin{verbatim}
#+Caption: This will become the title
#+Name: box:example
#+begin_infobox
Some text goes here. This will span the entire box.
In order to make better use of the available space and use two columns,
use the ~multicol~ package as here.
#+ATTR_LATEX: :options {2}
#+begin_multicols
\infoboxsection{Section 1}
- Key 1 :: Value 1
- Key 2 :: Value 2
- Key 3 :: Value 3
Actually there is no limit to what you can write here;
it's up to the author to structure the box as is appropriate.
\infoboxsection{Section 2}
| This | That |
|---------------+--------|
| Atomic number | 8 |
| Atomic mass | 16 |
| Half-life | Stable |
| Valence | 2 |
\infoboxsection{Note on sections}
Infobox sections do not show up on table of contents
and are not in fact sections in the ~\section~ sense.
#+end_multicols
#+end_infobox
\end{verbatim}
\section{Example \LaTeX{} usage}
\label{sec:org0fd6327}
Keep in mind that this is actually generated by the org \LaTeX{} generator,
with minimal reformatting.
\begin{verbatim}
\begin{infobox}
\caption{\label{box:example}This will become the title}
Some text goes here. This will span the entire box.
In order to make better use of the available space and use two columns,
use the \texttt{multicol} package as here.
\begin{multicols}{2}
\infoboxsection{Section 1}
\begin{description}
\item[{Key 1}] Value 1
\item[{Key 2}] Value 2
\item[{Key 3}] Value 3
\end{description}
Actually there is no limit to what you can write here;
it's up to the author to structure the box as is appropriate.
\infoboxsection{Section 2}
\begin{center}
\begin{tabular}{lr}
This & That\\
\hline
Atomic number & 8\\
Atomic mass & 16\\
Half-life & Stable\\
Valence & 2\\
\end{tabular}
\end{center}
\infoboxsection{Note on sections}
Infobox sections do not show up on table of contents
and are not in fact sections
in the \texttt{\textbackslash{}section} sense.
\end{multicols}
\end{infobox}
\end{verbatim}
\section{Result}
\label{sec:orgf26bdd8}
\begin{infobox}
\caption{\label{org9884f11}This will become the title}
Some text goes here. This will span the entire box.
In order to make better use of the available space and use two columns,
use the \texttt{multicol} package as here.
\begin{multicols}{2}
\infoboxsection{Section 1}
\begin{description}
\item[{Key 1}] Value 1
\item[{Key 2}] Value 2
\item[{Key 3}] Value 3
\end{description}
Actually there is no limit to what you can write here;
it's up to the author to structure the box as is appropriate.
\infoboxsection{Section 2}
\begin{center}
\begin{tabular}{lr}
This & That\\
\hline
Atomic number & 8\\
Atomic mass & 16\\
Half-life & Stable\\
Valence & 2\\
\end{tabular}
\end{center}
\infoboxsection{Note on sections}
Infobox sections do not show up on table of contents
and are not in fact sections in the \texttt{\textbackslash{}section} sense.
\end{multicols}
\end{infobox}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment