% Life of Rachael style package
% 2024-2025 rb

% The portions of this file that aren't lifted from CTAN are released under
% the "don't be an asshole" license. I'm not really pretentious enough to
% even MIT license this.

% Misc
\setlength\parindent{1.5em}
\flushbottom

% Emojis
\usepackage{emoji}
\usepackage{fontspec}
\newfontfamily\emojifont{Noto Color Emoji}[Renderer=Harfbuzz]

% Line breaks in paragraphs
\newcommand\stdclubpenalties{\clubpenalties 2 10000 2000}
\newcommand\stdwidowpenalties{\widowpenalties 2 10000 2000}
\stdclubpenalties
\stdwidowpenalties

% Table padding
\usepackage{array}
\setlength\extrarowheight{0.5em}

% Use smaller font for inline backtick text
\AddToHook{cmd/texttt/before}{\scriptsize}
\AddToHook{cmd/texttt/after}{\normalsize}

% Reduce vertical spacing for heading 4
\AddToHook{cmd/paragraph/before}{\vspace{0.1em - \medskipamount}}

% Fancy blockquotes
\usepackage{framed}
\AtBeginEnvironment{verbatim}{
  \small
  \vspace{1em}
  \begin{leftbar}
}
\AtEndEnvironment{verbatim}{
  \end{leftbar}
  \normalsize
}

% Bastard child of a verbatim and a blockquote
\newenvironment{barquote}
{
  \small
  \vspace{1.5em}
  \begin{leftbar}
}
{
  \end{leftbar}
  \vspace{0.5em}
  \normalsize
}

% Rounded image corners in message bubbles
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{tikz}

\let\realincludegraphics\includegraphics
\newcommand\includegraphicsrounded[2][]{%
  \begin{tikzpicture}
    \node[inner sep=0pt, clip, rounded corners=0.5em] {\realincludegraphics[#1]{#2}};
  \end{tikzpicture}%
}

% Wraps a sequence of message bubbles
\newenvironment{messagebubbleconv}
{
  \let\includegraphics\includegraphicsrounded
}
{
  \bigskip
  \let\includegraphics\realincludegraphics
}

%% Modified from https://ctan.org/tex-archive/macros/latex/contrib/messagebubbles %%

% dependencies
\usepackage{pbox}
\usepackage{fancybox}

\newcommand\bubblespace{\vspace{1em}}
\newcommand\bubblefont\small
\cornersize*{1em}

% commands
\newcommand{\messagebubbleleft}[2]{
  \bubblespace
  \bubblefont
  \begin{flushleft}
    \messagebubble{#2}
    \nopagebreak
    \\ % newline after bubble
    \timestampleft{#1}
    \adjustvspace
  \end{flushleft}
  \normalsize
  \bubblespace
}

\newcommand{\messagebubbleright}[2]{
  \bubblespace
  \bubblefont
  \begin{flushright}
    \messagebubble{#2}
    \nopagebreak
    \\ % newline after bubble
    \timestampright{#1}
    \adjustvspace
  \end{flushright}
  \normalsize
  \bubblespace
}

\newcommand{\messagebubble}[1]{
  \ovalbox{
    \pbox{\messagebubblewidth}{
      \textwidth1cm
      #1
    }
  }
}

\newcommand{\messagebubblewidth}{
  0.60\textwidth
}

\newcommand{\adjustvspace}{
  \vspace{-0.6cm}
}

\newcommand{\timestampright}[1]{
  \vspace{2pt}
  \timestamp{#1} % content of timestamp
  \hspace{1pt}
}

\newcommand{\timestampleft}[1]{
  \vspace{2pt}
  \hspace{1pt}
  \timestamp{#1} % content of timestamp
}

\newcommand{\timestamp}[1]{
  {\scriptsize \textbf{#1}} % bold and small
}

%% END messagebubbles lift %%
