%% -*- coding: utf-8 -*-
%% File: 00_shared/latex_styles/formatting.tex

%% --- Journal name header (show journal name as-is, without "Preprint submitted to" prefix) ---
\makeatletter
\def\ps@pprintTitle{%
  \def\@oddhead{\reset@font\footnotesize\itshape\@journal\hfill}%
  \let\@evenhead\@oddhead
  \def\@oddfoot{\reset@font\hfil\thepage\hfil}%
  \let\@evenfoot\@oddfoot}
\makeatother

%% --- Image width ---
\newlength{\imagewidth}
\newlength{\imagescale}

%% --- Line numbers ---
\linespread{1.2}
\linenumbers

%% --- Colors ---
\definecolor{GreenBG}{rgb}{0,1,0}
\definecolor{RedBG}{rgb}{1,0,0}

%% --- Highlight boxes ---
\newtcbox{\greenhighlight}[1][]{on line,colframe=GreenBG,colback=GreenBG!50!white,boxrule=0pt,arc=0pt,boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt,tcbox raise base}
\newtcbox{\redhighlight}[1][]{on line,colframe=RedBG,colback=RedBG!50!white,boxrule=0pt,arc=0pt,boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt,tcbox raise base}

\newcommand{\REDSTARTS}{\color{red}}
\newcommand{\REDENDS}{\color{black}}
\newcommand{\GREENSTARTS}{\color{green}}
\newcommand{\GREENENDS}{\color{black}}

%% --- Word count ---
\newread\wordcount
\newcommand\readwordcount[1]{%
\openin\wordcount=#1
\read\wordcount to \thewordcount
\closein\wordcount
\begingroup\sisetup{round-mode=none}\num{\thewordcount}\endgroup%
}

%% --- Text highlighting ---
\usepackage{soul}
\sethlcolor{yellow}

%% --- Reference handling ---
\usepackage{refcount}

\let\oldref\ref
\newcommand{\hlref}[1]{%
  \ifnum\getrefnumber{#1}=0
    \colorbox{yellow}{\ref*{#1}}%  % Use colorbox for references (no line break needed)
  \else
    \ref{#1}%
  \fi
}

% To add an 'S' prefixes to a reference
\newcommand*\sref[1]{S\hlref{#1}}
\newcommand*\sfref[1]{Supplementary Figure S\hlref{#1}}
\newcommand*\stref[1]{Supplementary Table S\hlref{#1}}
\newcommand*\smref[1]{Supplementary Materials S\hlref{#1}}

%%%% EOF