Sunday, 19 May 2013

Underlining fractions

Underlining fractions

I need to be able to underline equations involving fractions, which are aligned using the alignedat environment from amsmath. To be able to underline at all, I'm using the solution from this question - but when fractions get 'underlined', the line goes through the middle of the fraction rather than beneath it.
Also, is it possible to modify the underlining to make it a double underline?
Code - main file
\documentclass[answers]{exam}

\addtolength{\textwidth}{1cm}
\addtolength{\hoffset}{-0.5cm}
\addtolength{\textheight}{1cm}
\addtolength{\voffset}{-0.5cm}

\usepackage{xcolor} % Use colour!
\usepackage{titlesec} % Allow creation of new sectioning commands
\usepackage{amsmath} % Needed for splitting equations over multiple lines
\usepackage[normalem]{ulem} % Underlining effects
\usepackage{environ} % Tinkering with environments
\usepackage{gensymb} % Degree symbol
\usepackage[pdfstartview=FitH,bookmarks=true]{hyperref}
\usepackage[numbered]{bookmark} % PDF Bookmarks
\usepackage{tikz} % Underlining spanning alignment marks

\titleformat{\section}{\normalfont\large\bfseries}{Chapter }{0em}{\thesection: }
\renewcommand\sectionmark[1]{\markright{#1}} % Set up \rightmark
\renewcommand{\thesection}{\texorpdfstring{}{Chapter }\arabic{section}\texorpdfstring{}{:}} % Correct text for bookmarks

\titleclass{\exercise}{straight}[\section]  % Create new 'section' command for exercises - this replaces \subsection
\newcounter{exercise}
\titleformat{\exercise}{\normalfont\large\bfseries}{Exercise }{0em}{\theexercise}
\titlespacing*{\exercise}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\exerciseautorefname}{exercise}
\renewcommand{\theexercise}{\texorpdfstring{}{Exercise }\arabic{section}\Alph{exercise}} % Correct text for bookmarks
\makeatletter
\providecommand*{\toclevel@exercise}{2} % Make sure exercises appear below sections in bookmarks
\makeatother

\renewcommand{\thepartno}{\roman{partno}} % Format part numbers as lower-case roman numerals
\renewcommand{\solutiontitle}{\noindent} % Format solution - just print solution as entered
%\newcommand{\ans}[1]{\uuline{#1}} % Double underline final answer
\newcommand{\ans}[1]{\tikzmarkin{\theexercise\thequestion\thepartno}#1\tikzmarkend{\theexercise\thequestion\thepartno}} % Double underline final answer

\pagestyle{headandfoot} % Let's have both
\header{\oddeven{Exercise \theexercise}{Chapter \thesection: \rightmark}}{Core 1}{\oddeven{Chapter \thesection: \rightmark}{Exercise \theexercise}}
\headrule
\footer{\oddeven{}{\thepage}}{}{\oddeven{\thepage}{}}
\footrule


\NewEnviron{sol}{ % Align solutions sensibly
    \begin{solution}
        $\begin{alignedat}{2}
            \BODY
        \end{alignedat}$
    \end{solution}
}


\makeatletter % Use tikzmarks to underline across alignment marks
\tikzset{%
     remember picture with id/.style={%
       remember picture,
       overlay,
       save picture id=#1,
     },
     save picture id/.code={%
       \edef\pgf@temp{#1}%
       \immediate\write\pgfutil@auxout{%
         \noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
     },
     if picture id/.code args={#1#2#3}{%
       \@ifundefined{save@pt@#1}{%
         \pgfkeysalso{#3}%
       }{
         \pgfkeysalso{#2}%
       }
     }

No comments:

Post a Comment