8

I've got several documents that I would like to be able to format in different styles depending on the context of the presentation. The content should stay the same, but the formatting may need to change dramatically. I would like to be able store the content in key values to be able to more flexibly organize the formatting.

Here's a relatively minor MWE that nevertheless illustrates the underlying concept:

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfkeys}
\usepackage{etoolbox}
\usepackage{booktabs}
\usepackage{array}
\makeatletter
%-@-(1)---------------------------------------------------------------------
%% Inner workings which the user should not have to touch                   
%% assuming that I've set this up correctly.                                
\pgfkeys{/ae/present/info/.cd,
  presentation style/.store in=\ae@style,
  resource/.code=\ae@resource@code{#1},
}
\pgfkeys{/ae/resource/code/.cd,
  name/.store in=\ae@name,
  information/.code=\ae@information@code{#1},
}
\pgfkeys{/ae/information/code/.cd,
  given/.store in=\ae@given,
  aka/.store in=\ae@aka,
  conclusion/.store in=\ae@conclusion,
}

\long\def\presentinfo#1{\pgfkeys{/ae/present/info/.cd,#1}}

\long\def\ae@resource@code#1{%%
  \pgfkeys{/ae/resource/code/.cd,#1}
  \csname ae@finalize@formatting@\ae@style\endcsname
}

\long\def\ae@information@code#1{%%
  \bgroup
    \pgfkeys{/ae/information/code/.cd,#1}
    \csname ae@build@presentation@\ae@style\endcsname
  \egroup
}

%% Internal macros for formatting content
\def\ae@style{A}
\def\ae@name{}
\def\ae@given{}
\def\ae@aka{}
\def\ae@empty{}
\def\ae@conclusion{}
\def\ae@content@body{}

%% why do I have to "hide" \midrule like this?
\def\ae@midrule{\midrule}

%-@-(2)---------------------------------------------------------------------
%% User can play with the following macros to change the formatting         
%% of the output.                                                           
%%--------------------------------------------------------------------------
%% STYLE="A"                                                                
%%--------------------------------------------------------------------------
\def\ae@build@presentation@A{%%
  \xdef\ae@content@body{\expandonce\ae@content@body\noexpand\\
                           \noexpand\ae@midrule
                           \expandonce\ae@given     \noexpand & 
                           \expandonce\ae@aka       \noexpand & 
                           \expandonce\ae@conclusion }}

\def\ae@finalize@formatting@A{%%
  \par\vspace{2ex}%%
  \noindent
  \textbf{\ae@name:}\par\vspace{2ex}
  \begin{tabular}{>{\raggedright}p{3in}cp{3in}}
    \textsf{Given} & \hspace{3em} & \textsf{Conclusion}
    \ae@content@body
  \end{tabular}\par\vspace{1ex}
  \gdef\ae@content@body{}%%
}

%%--------------------------------------------------------------------------
%% STYLE="B"                                                                
%%--------------------------------------------------------------------------
\long\def\ae@build@presentation@B{%%
  \xdef\ae@content@body{\expandonce\ae@content@body
    \noexpand\item  
      \noexpand\textsf{Given:}    
        \noexpand\parbox[t]{\noexpand\dimexpr\noexpand\linewidth-2.5cm}{\noexpand\raggedright\expandonce\ae@given} 
        \noexpand\hspace*{\noexpand\fill}%%
        \ifx\ae@aka\ae@empty\else$\rightarrow$\fi
        \noexpand\textsf{\ae@aka}
        \noexpand\par
      \noexpand\textsf{Conclude:} \expandonce\ae@conclusion
  }}

\long\def\ae@finalize@formatting@B{%%
  \par
  \noindent
  $\left.
  \begin{minipage}{4in}
  \begin{itemize}
  \ae@content@body
  \end{itemize}
  \end{minipage} \right\}${\large if working with \sffamily\ae@name}\par \vspace{4ex}
  \def\ae@content@body{}%%
}

\makeatother
\begin{document}

\presentinfo{%%'
  presentation style=A,
  resource={%%
    name=Triangles,
    information={%%'
      given=Three pairs of sides are congruent,
      aka=SSS,
      conclusion=The two triangles are congruent.},
    information={
      given=Two pairs of sides are congruent and 1 pair of included angles is congruent,
      aka=SAS,
      conclusion=The two triangles are congruent,}
  }, 
  resource={%%
    name=Transversal,
    information={%%
      given=Alternate interior angles are congruent,
      conclusion=The  two lines are parallel.},
    information={%%
      given=Same side interior angles are supplementary,
      conclusion=The two lines are parallel.},
  }  
}

\end{document}

When using presentation style=A, the resulting document appears as

enter image description here

When using presentation style=B, the resulting document appears as

enter image description here

This gives me a wide degree of latitude in how I format my document. But my approach seems a bit too convoluted.

Is there a better approach? I would like to stick with pgfkeys. Is there a way in pgfkeys to avoid the nested calls to further key definitions? I tried creating a .style that would accomplish what I wanted but that didn't go anywhere.

On something of tangent to my primary question: I was having problems getting \midrule to behave. I had to bury it inside another macro. Otherwise, even with \noexpand\midrule I got alignment errors. Any ideas?

  • What do you mean by nested calls? Can you point out specifically which part makes you unhappy? – Symbol 1 Nov 20 '16 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.