# How to make boxes like these?

I'd like to have custom commands for making boxes that look like the Wolfram|Alpha entities in Mathematica notebooks:

\LinguisticAssistant{france}
\Entity{France}{country}


I've done the work of finding the colors, and defined them in my code. The fonts are as follows: - LinguisticAssistant: (the first box with the orange equals sign) uses Ariel - Entity: this uses bold and then smaller all-caps Helvitica.

This what I have so far:

\documentclass{article}
\usepackage{pstricks}
\usepackage{xcolor}
\definecolor{lightyellow}{RGB}{255, 250, 236}
\definecolor{textdark}{RGB}{100, 52, 20}
\definecolor{borderorange}{RGB}{253, 129, 36}
\definecolor{lightgray}{RGB}{214, 214, 214}
\definecolor{countrygray}{RGB}{153, 153, 153}
\begin{document}
\begin{pspicture}(5,5)
\psset{fillstyle=solid, framearc=.4, linecolor=borderorange, linewidth=.8pt}
\psframebox[fillcolor=lightyellow]{\textcolor{textdark}{France}  \textcolor{countrygray}{COUNTRY}}
\hspace{1cm}
\psset{fillstyle=solid, framearc=.2, linecolor=lightgray, linewidth=.4pt}
\psframebox[fillcolor=white]{\textcolor{black}{france}}
\end{pspicture}
\end{document}​


But I still don't know how to:

• make the little equal sign
• scale/format the text to look just like the images

I'm looking at the package tcolorbox now, not sure if it is easier or better than pstricks.

Update:

I made the equal sign icon as a little pdf.

• Show us what you've already tried. We're happy to help you if you're not fully able to implement what you want. We're here to help you, but not to do your work for you. – A.Ellett Oct 10 '18 at 16:23
• tcolorbox is definitely a good option. The manual details which keys are needed, so please post a minimal compilable code example of where you are stuck. – TeXnician Oct 10 '18 at 16:39

It's been a while since I've used pstricks, so I'll leave that for someone else to address. Also, I'm not fluent in using tcolorbox. So, that too I'll leave for someone else. But, I will show how you can do this from TikZ

This answer is broken into five parts:

• How to draw the France COUNTRY box. This is the most straight-forward.
• How to draw the Equal france box. I use a few more subtle tricks here.
• Customizing your own colors using RGB specifications.
• Using your own image file to create an Equal france box-like result
• Implementing this with macros

## Box for "France COUNTRY"

\documentclass[tikz,border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand\makegray[1]{\color{gray}{#1}}
\begin{document}

\begin{tikzpicture}

\node[rounded corners,
draw=orange,
fill=orange!25,text=black,font=\sffamily]
{France \makegray{COUNTRY}};

\end{tikzpicture}

\end{document}


## Box for "Equal france"

\documentclass[tikz,border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}

\newcommand\makegray[1]{\color{gray}{#1}}

\newsavebox\aeequalsign
\begin{lrbox}\aeequalsign
\begin{tikzpicture}[x={(4pt,0)},
y={(0,4pt)}]
\fill[orange] (0,0) rectangle (5,3);
\draw[white,line width=2pt] (1,1) -- ++ (3,0);
\draw[white,line width=2pt] (1,2) -- ++ (3,0);
\end{tikzpicture}
\end{lrbox}

\begin{document}

\begin{tikzpicture}

\node[inner sep=0pt]            (AEEQUAL)                  {\usebox{\aeequalsign}};
\node[anchor=west,
font=\sffamily\bfseries]  (FRANCE) at (AEEQUAL.east) {france};
\node[fit=(AEEQUAL) (FRANCE),inner ysep=5pt,inner xsep=0pt] (COMBINED) {};
\draw[rounded corners=4pt]
(AEEQUAL.north) |- (COMBINED.north east)
-- (COMBINED.south east) -| (AEEQUAL.south);

\end{tikzpicture}

\end{document}


## Colors:

If you don't like my colors, you can define your own, much like you did with pstricks using the \definecolor macro provided with xcolor (which is automatically loaded with TikZ).

\definecolor{<color name>}{rgb}{<decimal>,<decimal>,<decimal>}
\definecolor{<color name>}{RGB}{<int>,<int>,<int>}


Here is an implementation for this in TikZ:

\tikzset{define color/.code 2 args={\definecolor{#1}{RGB}{#2}}}


Then you can write

\begin{tikzpicture}
[
define color={borderorange}{253,129,36},
define color={lightyellow}{255,250,236},
]

\node[rounded corners,
draw=borderorange,
fill=lightyellow,text=black,font=\sffamily\bfseries]
{France \makegray{COUNTRY}};

\end{tikzpicture}


## Including image files:

If you have an image file you would already like to include, that's straight-forward.

Just repurpose the code above for the equal sign as follows:

\newsavebox\aeequalsign
\begin{lrbox}\aeequalsign
\includegraphics[width=2em]{image/no_you_cant}
\end{lrbox}


## Macros for in-text implementation

\LinguisticAssitant
\Entity


to allow you to more easily create something like the following:

I've also added a couple more features: in particular, I've taken into account that these might be used in-line (as in the image above), so I set the baseline for the graphic to match the textual baseline. Also, I've added the following line to \LinguisticAssistant

\path (COMBINED.north) ++ (0,\lineskip) node[inner sep=0pt] {};


which should avoid the appearance of this image crashing into the line above it.

You can add something similar to the bottom too

\path (COMBINED.south) ++ (0,-\lineskip) node[inner sep=0pt] {};


if you wish to add more space below the image. But, I've not done that with this code. Additionally, you can tweak the inner sep to create a more rigid space.

This was executed using

\documentclass{article}
\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}

\newcommand\makegray[1]{\color{gray}{#1}}

\newsavebox\aeequalsign
\begin{lrbox}\aeequalsign
\includegraphics[height=3ex]{image/no_you_cant}
\end{lrbox}

\tikzset{define color/.code 2 args={\definecolor{#1}{RGB}{#2}}}
\tikzset{define color={borderorange}{253,129,36},
define color={lightyellow}{255,250,236},
}

\newcommand\Entity[2]{%%
\begin{tikzpicture}[baseline={(EQUALITY.base)}]
\node[rounded corners,
draw=borderorange,
fill=lightyellow,text=black,font=\sffamily\bfseries]
(EQUALITY)
{#1 \makegray{#2}};
\end{tikzpicture}}

\newcommand\LinguisticAssistant[1]{%%
\begin{tikzpicture}[baseline={(FRANCE.base)}]
\node[inner sep=0pt]            (AEEQUAL)                  {\usebox{\aeequalsign}};
\node[anchor=west,
font=\sffamily\bfseries]  (FRANCE) at (AEEQUAL.east) {#1};
\node[fit=(AEEQUAL) (FRANCE),inner ysep=5pt,inner xsep=0pt] (COMBINED) {};
\draw[rounded corners=4pt]
(AEEQUAL.north) |- (COMBINED.north east)
-- (COMBINED.south east) -| (AEEQUAL.south);
\path (COMBINED.north) ++ (0,\lineskip) node[inner sep=0pt] {};
\end{tikzpicture}}

\begin{document}

\LinguisticAssistant{ARMA} \Entity{virumque}{cano}, Troiae qui primus ab oris
Italiam, fato profugus, Laviniaque venit
litora, multum ille et terris iactatus et alto
vi superum saevae memorem Iunonis ob iram;
multa quoque et bello passus, dum conderet urbem,
inferretque deos Latio, genus unde Latinum,
Albanique patres, atque altae moenia Romae.

\LinguisticAssistant{Musa}, \Entity{mihi}{causas memora}, quo numine laeso,
quidve dolens, regina deum tot volvere casus
insignem pietate virum, tot adire labores
impulerit.  Tantaene animis caelestibus irae?

\LinguisticAssistant{Urbs} \Entity{antiqua}{fuit}, Tyrii tenuere coloni,
Karthago, Italiam contra Tiberinaque longe
ostia, dives opum studiisque asperrima belli;
quam Iuno fertur terris magis omnibus unam
posthabita coluisse Samo; hic illius arma,
hic currus fuit; hoc regnum dea gentibus esse,
si qua fata sinant, iam tum tenditque fovetque.
Progeniem sed enim Troiano a sanguine duci
audierat, Tyrias olim quae verteret arces;
hinc populum late regem belloque superbum
venturum excidio Libyae:  sic volvere Parcas.
Id metuens, veterisque memor Saturnia belli,
prima quod ad Troiam pro caris gesserat Argis---
necdum etiam causae irarum saevique dolores
exciderant animo:  manet alta mente repostum
iudicium Paridis spretaeque iniuria formae,
et genus invisum, et rapti Ganymedis honores.
His accensa super, iactatos aequore toto
Troas, reliquias Danaum atque immitis Achilli,
arcebat longe Latio, multosque per annos
errabant, acti fatis, maria omnia circum.
Tantae molis erat Romanam condere gentem!

\end{document}

• Thanks for your response, but I'm trying to get the exact pixel-for-pixel look - i.e. color/fonts - see in my question where I added them. – M.R. Oct 10 '18 at 17:42
• @M.R.: You can, of course, just use the fonts you specify. The basic principle in the box designs remain the same. Do you know how to add fonts? – Werner Oct 10 '18 at 17:46
• No but I added the equals icon in a link - if you can try adding that? – M.R. Oct 10 '18 at 18:11
• @M.R. updated per your most recent request. Everything else in terms of pixel-for-pixel, that's up to you. I don't necessarily have access to the same fonts as you, for example. – A.Ellett Oct 10 '18 at 18:22
• @A.Ellett See my edit, I can't get your custom commands to work - I use TexPad – M.R. Oct 10 '18 at 20:34

A solution using pstricks below. The MWE shows four attempts: 1. default sans serif font, rectangular equals box; 2. using Helvetica, square equals box with rounded corners; 3. using image of equals box provided by the OP; 4. inline in a paragraph by adjusting PSTricks coordinates.

\documentclass{article}
\usepackage{pstricks}
\usepackage{xcolor}
\usepackage{helvet} % attempt 2
\usepackage{graphicx} % attempt 3
\definecolor{lightyellow}{RGB}{255, 250, 236}
\definecolor{textdark}{RGB}{100, 52, 20}
\definecolor{borderorange}{RGB}{253, 129, 36}
\definecolor{lightgray}{RGB}{214, 214, 214}
\definecolor{countrygray}{RGB}{153, 153, 153}
\begin{document}
\begin{pspicture}(5,5)
\psset{fillstyle=solid, framearc=.4, linecolor=borderorange, linewidth=.8pt}
\rput[l](0,1){\psframebox[fillcolor=lightyellow]{\textcolor{textdark}{\textsf{\textbf{France}}}  \textcolor{countrygray}{\footnotesize\textsf{COUNTRY}}}}

\psset{fillstyle=solid, framearc=.2, linecolor=lightgray, linewidth=.4pt}
\rput[l](0.15,2){\psframebox[fillcolor=white]{\textcolor{black}{\textsf{\phantom{.}france}}}} % attempt 1: \phantom{x}
% \psset{framearc=.5} % attempt 2
% \rput[l](0,1){\psframebox[fillcolor=orange,framesep=1pt]{\vphantom{|}\tiny\textcolor{white}{\raisebox{1.2pt}{=}}}} % attempt 1: framesep 2pt
\rput[l](0,2){\includegraphics[width=3mm]{small-equals-icon.eps}} % attempt 3
\end{pspicture}

% attempt 4
\newcommand\LinguisticAssistant[2]{%%
\begin{pspicture}(#2,0.4)
\psset{fillstyle=solid, framearc=.2, linecolor=lightgray, linewidth=.4pt}
\rput[l](0.15,0.1){\psframebox[fillcolor=white]{\textcolor{black}{\textsf{\phantom{.}#1}}}}
\rput[l](0,0.1){\includegraphics[width=3mm]{small-equals-icon.eps}}
\end{pspicture}
}

hic currus fuit; hoc regnum dea gentibus esse,
si qua fata sinant, iam tum tenditque fovetque.
Progeniem sed enim Troiano \LinguisticAssistant{France}{1.5}
a sanguine duci audierat, Tyrias olim quae verteret arces;
hinc populum late regem belloque superbum
venturum excidio Libyae:  sic volvere Parcas.
Id metuens, veterisque memor Saturnia belli,
prima quod ad Troiam pro caris gesserat Argis---
necdum etiam causae irarum

\end{document}


Attempt 1:

Attempt 2:

Attempt 3:

Attempt 4:

The positioning is done using \rput with coordinates. This allows to place a box with an = (attempt 1 and 2) or an included graphic (attempt 3 and 4) on top of the box with france. The text in the box has been shifted a bit to the right using a phantom letter (which is not printed but the space it would occupy if it was 'real' is taken into account). The box with the = sign (attempt 1 and 2) has a bit smaller margin (2pt for attempt 1) to look more like the original picture. In attempt 2 the box is more square using framesep=1pt and a vertical phantom |, rounded corners with framearc=.5, equal sign slightly raised with \raisebox. The font is sans serif, using \textsf (in combination with boldface \textbf for the second France), set to Helvetica with \usepackage{helvet} for attempt 2,3,4. The text COUNTRY is made smaller with \footnotesize to simulate small caps.

In attempt 3 and 4 the \framebox with the equal sign is replaced by \includegraphics, which requires \usepackage{graphicx}. If the compile sequence latex-dvips-ps2pdf is used the pdf image needs to be converted to eps, in Linux for example with pdftops -eps small-equals-icon.pdf. If xelatex is used for the compilation the conversion is not necessary, but in that case a different approach is needed to use Helvetica-like fonts.

A pspicture can be used inline in a paragraph without any further adjustments. However, the space that is allocated for the picture depends on the size specified for the picture and the coordinates of the elements within the picture. In the MWE the picture is too large (5,5) for the contents, and the elements are partly drawn outside of the picture area due to the coordinates used. Adjusting the size and the coordinates therefore creates a suitable inline picture. The MWE shows the idea for the first picture, adjusting the second picture is left as an exercise for the reader. Because the width of the inline picture may differ it has been added as an argument to \LinguisticAssistant.

• This is almost exactly it! See my updated question where I added the exact fonts - can you tweak the equal sign to make it look more like the one I added? – M.R. Oct 10 '18 at 17:43
• @M.R. is this any better? – Marijn Oct 10 '18 at 18:08
• Great! one last thing - I added the equals icon in a link - can you add that? – M.R. Oct 10 '18 at 18:10
• @M.R. added - note that the pdf needs to be converted first if you use latex-dvips-ps2pdf. – Marijn Oct 10 '18 at 18:38
• See my edit, sooo close - but I'd like these boxes to work in a paragraph... – M.R. Oct 10 '18 at 20:33

Did someone mention tcolorbox?

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{helvet}

\definecolor{lightyellow}{RGB}{255, 250, 236}
\definecolor{textdark}{RGB}{100, 52, 20}
\definecolor{borderorange}{RGB}{253, 129, 36}
\definecolor{lightgray}{RGB}{214, 214, 214}
\definecolor{countrygray}{RGB}{153, 153, 153}

\newcommand{\Entity}[3][]{%
\tcbox[colframe=borderorange, colback=lightyellow,
nobeforeafter, tcbox raise base,
boxsep=0mm, left=2mm, right=2mm, arc=.4mm,
fontupper=\sffamily, #1]{%
\textcolor{textdark}{\bfseries #2}%
\ \textcolor{countrygray}{#3}}%
}

\newcommand{\LinguisticAssistant}[2][]{%
\tcbox[enhanced,
colframe=lightgray, colback=white,
nobeforeafter, tcbox raise base,
boxsep=0mm, left=2mm, right=2mm, arc=.2mm,
enlarge left by=1.5mm,
fontupper=\sffamily,
overlay={\node[inner sep=0pt, outer sep=0pt] at (frame.west) {\includegraphics[width=3mm]{small-equals-icon}};},
#1]{#2}%
}

\begin{document}

\Entity{France}{COUNTRY}
\LinguisticAssistant{france}

The \texttt{Entity} box looks like \Entity{France}{COUNTRY} and this one, \LinguisticAssistant{france},  is called \texttt{LinguisticAssistant}.
\end{document}​


• I always prefer using an existing package and get the best out of it. A very simple solution with a great result. Well done! – jqueralt Oct 18 '18 at 8:21
• @jqueralt Gràcies! – Ignasi Oct 18 '18 at 8:48
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7200815081596375, "perplexity": 11539.378103334324}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-50/segments/1606141195069.35/warc/CC-MAIN-20201128040731-20201128070731-00207.warc.gz"}