Skip to content

Commit

Permalink
Examples tex files and output figures for annotated equations in Late…
Browse files Browse the repository at this point in the history
…x using Tikz. First checkin
  • Loading branch information
Sibin Mohan committed Jan 10, 2022
1 parent 3e23d50 commit 2795534
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Makefile for Latex
# Created by Sibin M.
# Date : May 15, 2004.

# LATEX = pdflatex
LATEX = xelatex
BIBTEX = bibtex
DVIPS = dvips
DVIPDF = dvipdf
PDFTOOO = pdf2oo -batch
PSTOPDF = ps2pdf
PDFTOPS = pdf2ps
ACROBAT_COMPATIBILITY = 1.5

# MAIN_FILE_NAME = rtss09
MAIN_FILE_NAME = $(shell egrep -l '^[^%]*\\begin\{document\}' *.tex | gawk -F . 'BEGIN {filename;} /tex/ { filename = $$1; } END{printf(filename);}' )
BIB_FILES = mybib.bib realime.bib ada9x.bib sibin.bib power.bib zhu.bib arch.bib
# BIB_FILES := $(shell perl -ne '($$_)=/^[^%]*\\bibliography\{(.*?)\}/;@_=split /,/;foreach $$b (@_) {print "$$b.bib "}' $(SRC))

EMBED_SRC := $(MAIN_FILE_NAME)
EMBED_RESULT := $(MAIN_FILE_NAME)_embedded
EMBED = gs -sDEVICE=pdfwrite -q -dBATCH -dNOPAUSE -dSAFER -dPDFX -dPDFSETTINGS=/prepress -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -sOutputFile=$(EMBED_RESULT).ps -c '<> setdistillerparams' -f $(EMBED_SRC).ps -c quit

GOALS = $(MAIN_FILE_NAME).dvi

#%.pdf: %.dvi
# $(DVIPDF) $<
# $(EMBED)

%.pdf: %.ps
# $(DVIPDF) $<
# $(EMBED)
# $(PDFTOPS) $(EMBED_RESULT).pdf
# cp $(EMBED_RESULT).ps $(EMBED_RESULT)_temp.ps
$(EMBED)
$(PSTOPDF) -dCompatibilityLevel=$(ACROBAT_COMPATIBILITY) -dMAxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sPAPERSIZE=letter $(EMBED_RESULT).ps
cp $(EMBED_RESULT).pdf $(MAIN_FILE_NAME)_submission.pdf


%.ps: %.dvi
$(DVIPS) -o $(MAIN_FILE_NAME).ps $<

%.odp: %.pdf
$(PDFTOOO) $(MAIN_FILE_NAME).pdf

%.dvi: $(MAIN_FILE_NAME)
$(LATEX) $(MAIN_FILE_NAME)
$(BIBTEX) $(MAIN_FILE_NAME)
$(LATEX) $(MAIN_FILE_NAME)
$(LATEX) $(MAIN_FILE_NAME)

all: clean $(GOALS)

$(MAIN_FILE_NAME).dvi: $(MAIN_FILE_NAME).tex
$(LATEX) $(MAIN_FILE_NAME)
$(BIBTEX) $(MAIN_FILE_NAME)
$(LATEX) $(MAIN_FILE_NAME)
$(LATEX) $(MAIN_FILE_NAME)

clean:
rm -rf *.dvi *.log *.bbl *.blg *.aux *~

clobber:
make clean
rm -rf $(MAIN_FILE_NAME).pdf $(MAIN_FILE_NAME).ps $(MAIN_FILE_NAME).odt
10 changes: 10 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This repository provides four examples of annotated equations:

1. [example_prob.tex] A simple one inside the equation construct, in a double column format
2. [example_prob2.tex] A more complex one, but this time inside the figure construct in a double column format
3. [example_laplace.tex] Inside the wrapfigure construct but for a single column format
4. [example_overlay.tex] More complicated examples, side-by-side using the minipage construct in a single column format

The folder, "example_output_figs" includes figures that show the outputs of the above four cases.

Note: the main latex file, "eqn_annotate.tex" includes many latex packages and some definitions that are required.
125 changes: 125 additions & 0 deletions eqn_annotate.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
\documentclass[letterpaper,twocolumn,10pt]{article}

\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{tikzmark}
\usetikzlibrary{calc}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{mathtools, nccmath}
\usepackage{wrapfig}
\usepackage{comment}

% To generate dummy text
\usepackage{blindtext}


%color
%\usepackage[dvipsnames]{xcolor}
% \usepackage{xcolor}


%\usepackage[pdftex]{graphicx}
\usepackage{graphicx}
% declare the path(s) for graphic files
%\graphicspath{{../Figures/}}

% extensions so you won't have to specify these with
% every instance of \includegraphics
% \DeclareGraphicsExtensions{.pdf,.jpeg,.png}

% for custom commands
\usepackage{xspace}

% table alignment
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
\newcolumntype{X}[1]{>{\RaggedRight\hspace*{0pt}}p{#1}}

% color box
\usepackage{tcolorbox}


% for tikz
\usepackage{tikz}
%\usetikzlibrary{trees}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees,mindmap}
% \usepackage{forest}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}
\colorlet{linecol}{black!75}
\usepackage{xkcdcolors} % xkcd colors


% for colorful equation
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{tikzmark}
\usetikzlibrary{calc}
% Commands for Highlighting text -- non tikz method
\newcommand{\highlight}[2]{\colorbox{#1!17}{$\displaystyle #2$}}
%\newcommand{\highlight}[2]{\colorbox{#1!17}{$#2$}}
\newcommand{\highlightdark}[2]{\colorbox{#1!47}{$\displaystyle #2$}}

% my custom colors for shading
\colorlet{mhpurple}{Plum!80}


% Commands for Highlighting text -- non tikz method
\renewcommand{\highlight}[2]{\colorbox{#1!17}{#2}}
\renewcommand{\highlightdark}[2]{\colorbox{#1!47}{#2}}

% Some math definitions
\newcommand{\lap}{\mathrm{Lap}}
\newcommand{\pr}{\mathrm{Pr}}

\newcommand{\Tset}{\mathcal{T}}
\newcommand{\Dset}{\mathcal{D}}
\newcommand{\Rbound}{\widetilde{\mathcal{R}}}

\begin{document}

\title{Annotated Equations in Latex Using Tikz}

\author{
{\bf Sibin Mohan}\\
{https://sibin.github.io/sibin}
% copy the following lines to add more authors
% \and
% {\rm Name}\\
%Name Institution
} % end author

\maketitle

% Start with Two-Column Examples
\blindtext
\vspace{2\baselineskip}

\input{example_prob}

% More complex anmnotations
\blindtext
\blindtext
\input{example_prob2.tex}

% Single column with more complex examples
\onecolumn

% Wrapping text arond equations
\blindtext
\input{example_laplace.tex}

% Annotated Equations Side-by-Side
\blindtext
\input{example_overlay.tex}

\blindtext

\end{document}
15 changes: 15 additions & 0 deletions example_eqn1.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
\begin{figure}
\vspace{0.5\baselineskip}
\begin{equation}
\Pr[\mathcal{R}(\tikzmarknode{ts}{\highlight{red}{$\tau_i$}},\tikzmarknode{js}{\highlight{blue}{$j$}})\in \mathcal{S}] \leq e^\epsilon \Pr[\mathcal{R}(\tikzmarknode{td}{\highlight{red}{$\tau_i'$}},\tikzmarknode{jd}{\highlight{blue}{$j'$}})\in \mathcal{S}]
\label{eq:dp_one_instance}
\end{equation}
\begin{tikzpicture}[overlay,remember picture,>=stealth,nodes={align=left,inner ysep=1pt},<-]
% Ts to Td
\path (ts.north) ++ (-1.5em,2em) node[anchor=south west,color=red!67] (scalep){\textbf{$\tau_i,\tau' \in \Gamma$}, \textbf{the set of Tasks}};
\draw[<->,color=red!57] (ts.north) -- ++(0,0.67) -| node[] {} (td.north);
% js to jd
\path (js.south) ++ (3em,-3.3em) node[anchor=south west,color=blue!67] (scalep){\textbf{$j,j'\in \mathbb{N}$}};
\draw[<->,color=blue!57] (js.south) -- ++(0,-0.67) -| node[] {} (jd.south);
\end{tikzpicture}
\end{figure}
18 changes: 18 additions & 0 deletions example_laplace.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
\begin{wrapfigure}{l}{0.5\columnwidth}
\vspace{\baselineskip}
\begin{equation}
\label{eq:laplace_density}
\lap (x\ |\ \tikzmarknode{u}{\highlight{red}{$\mu$}}, \tikzmarknode{b}{\highlight{blue}{b}}) = \frac{1}{2b} \mathrm{exp}(-\frac{|x-\mu|}{b})
\end{equation}
\begin{tikzpicture}[overlay,remember picture,>=stealth,nodes={align=left,inner ysep=1pt},<-]
% For "mu"
\path (u.north) ++ (0,2em) node[anchor=south west,color=red!67] (scalep){\textbf{location parameter, mean}};
\draw [color=red!57](u.north) |- ([xshift=-0.3ex,color=red]scalep.south east);
% For "b"
\path (b.south) ++ (0,-1.5em) node[anchor=north west,color=blue!67] (mean){\textbf{$b >0$, scale parameter}};
\draw [color=blue!57](b.south) |- ([xshift=-0.3ex,color=blue]mean.south east);
\end{tikzpicture}
\vspace{0.5\baselineskip}
\caption{An example in the single column format using the wrapfig construct.}
\vspace{0.5\baselineskip}
\end{wrapfigure}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example_output_figs/simple_annotated_equation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions example_overlay.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
\begin{figure}[h]
\vspace{\baselineskip}
\begin{minipage}{0.5\columnwidth}
\begin{equation*}
\label{eq:ab_flushing}
N_{i} =
\color{purple}
\overbrace{
\tikzmarknode{qp}{\highlight{purple}{ \color{black} $Q_p$ }} \color{black}\big( \tikzmarknode{tj1}{\highlight{NavyBlue}{ \color{black} $t_{j+1}$}} \color{black} - \tikzmarknode{tj}{\highlight{Bittersweet}{ \color{black} $t_{j}$}}
\color{black}\big) |
\tikzmarknode{aj}{\highlight{purple}{ \color{black} $\forall j$ }}
\color{black}\big)
}^{\substack{\text{\sf \footnotesize \textcolor{purple!85}{Some annotation about the
}} \\ \text{\sf \footnotesize \textcolor{purple!85}{entire equation here.
}} } }
\end{equation*}
\vspace*{0.5\baselineskip}
\begin{tikzpicture}[overlay,remember picture,>=stealth,nodes={align=left,inner ysep=1pt},<-]
% For "t_{j+1}"
\path (tj1.north) ++ (-3.85,-1.8em) node[anchor=north west,color=NavyBlue!85] (tj1text){\textsf{\footnotesize property of (j+1)\textsuperscript{th} item}};
\draw [color=NavyBlue](tj1.south) |- ([xshift=-0.3ex,color=NavyBlue]tj1text.south west);
% For "t_{j}"
\path (tj.north) ++ (0.3,-1.8em) node[anchor=north west,color=Bittersweet!85] (tjtext){\textsf{\footnotesize j\textsuperscript{th} item}};
\draw [color=Bittersweet](tj.south) |- ([xshift=-0.3ex,color=Bittersweet]tjtext.south east);
\end{tikzpicture}
\end{minipage}
\hfil
\begin{minipage}{0.5\columnwidth}
\begin{equation*}
\label{eq:ab_crypto}
\hspace*{-6em}
X_{i} = \frac{1}{\sum_{i=1}^{\tikzmarknode{n}{\highlight{purple}{N}}}
\sum_{j=1}^{\tikzmarknode{mi}{\highlight{NavyBlue}{$M_i$}}}
\tfrac{\tikzmarknode{lij}{\highlight{Bittersweet}{$l_i^j$}}}{\tikzmarknode{lmax}{\highlight{OliveGreen}{$l^{max}$}}}
}
\end{equation*}
\vspace*{0.8\baselineskip}
\begin{tikzpicture}[overlay,remember picture,>=stealth,nodes={align=left,inner ysep=1pt},<-]
% For "N"
\path (n.north) ++ (0,1.8em) node[anchor=south east,color=Plum!85] (ntext){\textsf{\footnotesize number of objects}};
\draw [color=Plum](n.north) |- ([xshift=-0.3ex,color=Plum]ntext.south west);
% For "M_i"
\path (mi.north) ++ (0,3.5em) node[anchor=north west,color=NavyBlue!85] (mitext){\textsf{\footnotesize number of other objects}};
\draw [color=NavyBlue](mi.north) |- ([xshift=-0.3ex,color=NavyBlue]mitext.south east);
% For "l_i^j"
\path (lij.north) ++ (0,1.9em) node[anchor=north west,color=Bittersweet!85] (lijtext){\textsf{\footnotesize size of j\textsuperscript{th} service}};
\draw [color=Bittersweet](lij.north) |- ([xshift=-0.3ex,color=Bittersweet]lijtext.south east);
% For "l_i^max"
\path (lmax.north) ++ (-2.7,-1.5em) node[anchor=north west,color=xkcdHunterGreen!85] (lmaxtext){\textsf{\footnotesize maximum obj size}};
\draw [color=xkcdHunterGreen](lmax.south) |- ([xshift=-0.3ex,color=xkcdHunterGreen]lmaxtext.south west);
\end{tikzpicture}
\end{minipage}
\caption{Two Equations side-by-side using minipage and figure constructs.}
\end{figure}
14 changes: 14 additions & 0 deletions example_prob.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
\begin{equation}
\vspace{\baselineskip}
\label{eq:epsilon}
\pr[\tikzmarknode{x}{\highlight{red}{$\mathcal{X}(\cdot)$}}\in \tikzmarknode{s}{\highlight{blue}{$\mathcal{S}$}}] \leq e^\epsilon \cdot \pr[\mathcal{X}(\cdot)\in \mathcal{S}]
\end{equation}
\begin{tikzpicture}[overlay,remember picture,>=stealth,nodes={align=left,inner ysep=1pt},<-]
% For "X"
\path (x.north) ++ (0,2em) node[anchor=south east,color=red!67] (scalep){\textbf{system state}};
\draw [color=red!87](x.north) |- ([xshift=-0.3ex,color=red]scalep.south west);
% For "S"
\path (s.south) ++ (0,-1.5em) node[anchor=north west,color=blue!67] (mean){\textbf{$\mathcal{S} \subseteq \mathrm{Range}(\mathcal{X})$}};
\draw [color=blue!57](s.south) |- ([xshift=-0.3ex,color=blue]mean.south east);
\end{tikzpicture}

17 changes: 17 additions & 0 deletions example_prob2.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
\begin{figure}[htb]
\vspace{2\baselineskip}
\begin{equation}
\pr[\mathcal{R}(\tikzmarknode{ts}{\highlight{red}{$\tau_i$}},\tikzmarknode{js}{\highlight{blue}{$j$}})\in \mathcal{S}] \leq e^\epsilon \pr[\mathcal{R}(\tikzmarknode{td}{\highlight{red}{$\tau_i'$}},\tikzmarknode{jd}{\highlight{blue}{$j'$}})\in \mathcal{S}]
\label{eq:dp_one_instance}
\end{equation}
\begin{tikzpicture}[overlay,remember picture,>=stealth,nodes={align=left,inner ysep=1pt},<-]
% Ts to Td
\path (ts.north) ++ (-1.5em,2em) node[anchor=south west,color=red!67] (scalep){\textbf{$\tau_i,\tau' \in \Gamma$}, \textbf{the set of Tasks}};
\draw[<->,color=red!57] (ts.north) -- ++(0,0.67) -| node[] {} (td.north);
% js to jd
\path (js.south) ++ (3em,-3.3em) node[anchor=south west,color=blue!67] (scalep){\textbf{$j,j'\in \mathbb{N}$}};
\draw[<->,color=blue!57] (js.south) -- ++(0,-0.67) -| node[] {} (jd.south);
\end{tikzpicture}
\vspace{\baselineskip}
\caption{A More Complex Example for Annotated Equations, this time inside a figure contruct.}
\end{figure}

0 comments on commit 2795534

Please sign in to comment.