\documentclass[12pt,a4paper]{article}

\usepackage{geometry}
\geometry{%
  a4paper,
  lmargin=1.7cm,
  rmargin=1.7cm,
  tmargin=2cm,
  bmargin=2cm,
  footskip=0pt,
  headheight=12pt}

\usepackage{amsmath}
\usepackage{amssymb}
\let\ge=\geqslant  \let\le=\leqslant
\usepackage{calc}
\usepackage{tikz}[2013/12/13 v3.0.0]
\usetikzlibrary{calc}
\tikzset{above/.default=6pt}
\tikzset{regular/.style={sloped, above}}
\tikzset{hidden/.style={sloped, above, fill=yellow!80!white}}

\newsavebox\templateimagebox
\newdimen\templateimagewd
\newif\iftesting  % say \testingtrue to have \uptriangle etc. use
                  % simple parameters like {Q1} instead of {{regular}{Q1}}

\usepackage[export]{adjustbox}

\newcommand{\image}[1]{\includegraphics[max height=0.3\trad, max width=0.8\sidelength]{#1}}
% There might be a nicer way to do the following, but I haven't yet
% found it.
\newcommand{\imagecap}[2]{%
  \savebox{\templateimagebox}{\includegraphics[max height=0.3\trad, max width=0.8\sidelength]{#1}}%
  \setlength{\templateimagewd}{\wd\templateimagebox}%
  \hbox to \templateimagewd{%
    \begin{minipage}{\templateimagewd}%
      \usebox{\templateimagebox}\\
      \hbox to \templateimagewd{\hss #2\hss}%
    \end{minipage}}}

% Usage of these macros:
% First do: \setshapesize{size} where size is the side length of
% the triangle/square given in cm with no units
% Then:
% \...triangle{(x0,y0)}{label1}{label2}{label3}
% where the first argument is the coordinate of the centre,
% and the labels are placed anticlockwise in the following order:
% \uptriangle: base, right, left
% \downtriangle: base, left, right
% \lefttriangle: right, top, bottom
% \righttriangle: left, bottom, top

\newlength\sidelength % side length
\newlength\trad % triangle circumradius
\newlength\srad % square circumradius
\newcommand{\setshapesize}[1]{%
 \pgfmathsetlength\sidelength{#1*72.27/2.54}
 \pgfmathsetlength\trad{(#1*72.27/2.54) / sqrt(3)}
 \pgfmathsetlength\srad{(#1*72.27/2.54) / sqrt(2)}
}
\setshapesize{10} % default, so table output works

\newcommand{\makestyles}[3]{%
  \iftesting
    \def#1{regular}
    \def#2{#3}
  \else
    % split #3 into {style}{text}
    \makestylesa#1#2#3
  \fi
}
\newcommand{\makestylesa}[4]{%
  \def#1{#3}
  \def#2{#4}
}

\newcommand{\tiltedtriangle}[7]{%
  \coordinate (a) at ($ #1 +({#2-150}:\trad) $);
  \coordinate (b) at ($ #1 +({#2-30}:\trad) $);
  \coordinate (c) at ($ #1 +({#2+90}:\trad) $);

  \makestyles\stylea\contenta{#3}
  \makestyles\styleb\contentb{#4}
  \makestyles\stylec\contentc{#5}

  \draw[allow upside down]
    (a) -- node[\stylea] {\contenta}
    (b) -- node[\styleb] {\contentb}
    (c) -- node[\stylec] {\contentc}
    cycle;
  % If card number is empty, don't draw circle around number
  \def\templabel{#6}
  \ifx\templabel\empty
  \else
    \node[circle,draw,thin,inner sep=1pt,rotate=#7] at ($ #1 $) {#6};
  \fi
}

\newcommand{\uptriangle}[6]{%
  \tiltedtriangle{#1}{0}{#2}{#3}{#4}{#5}{#6}
}
\newcommand{\downtriangle}[6]{%
  \tiltedtriangle{#1}{180}{#2}{#3}{#4}{#5}{#6}
}
\newcommand{\lefttriangle}[6]{%
  \tiltedtriangle{#1}{90}{#2}{#3}{#4}{#5}{#6}
}
\newcommand{\righttriangle}[6]{%
  \tiltedtriangle{#1}{270}{#2}{#3}{#4}{#5}{#6}
}

\newcommand{\tiltedsquare}[8]{%
  \coordinate (a) at ($ #1 +({#2-135}:\srad) $);
  \coordinate (b) at ($ #1 +({#2-45}:\srad) $);
  \coordinate (c) at ($ #1 +({#2+45}:\srad) $);
  \coordinate (d) at ($ #1 +({#2+135}:\srad) $);

  \makestyles\stylea\contenta{#3}
  \makestyles\styleb\contentb{#4}
  \makestyles\stylec\contentc{#5}
  \makestyles\styled\contentd{#6}

  \draw[allow upside down]
    (a) -- node[\stylea] {\contenta}
    (b) -- node[\styleb] {\contentb}
    (c) -- node[\stylec] {\contentc}
    (d) -- node[\styled] {\contentd}
    cycle;
  % If card number is empty, don't draw circle around number
  \def\templabel{#7}
  \ifx\templabel\empty
  \else
    \node[circle,draw,thin,inner sep=1pt,rotate=#8] at ($ #1 $) {#7};
  \fi
}

\newcommand{\upsquare}[7]{%
  \tiltedsquare{#1}{0}{#2}{#3}{#4}{#5}{#6}{#7}
}

\pagestyle{empty}
\setlength{\parindent}{0pt}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
