%% file: cutmultipanel.tex = demo panel cutting into multi-panel figure
%% last: Oct 11 2015  Rob Rutten  Deil
%% note: the example (below the macros) produces a 3x2 panel assembly
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{article} 
\usepackage{epsfig}
\textheight=500cm  %RR max permitted, for wide hi-res assemblies
\textwidth=500cm   %RR max permitted, for wide hi-res assemblies
\pagestyle{empty}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MULTI-FILE FIGURE
%% macros to combine separate postscript files into one multi-panel figure
%% template in file cutmultipanel.tex
%% Manual:
%% - measure panel bounding boxes with GHOSTVIEW (gv) in bp units for \setbb
%%   - outer lower-left corner (just outside axis labels)
%%   - inner lower-left corner (between labels and numbers,
%%       or just outside the frame or just outside outward ticks)
%%   - upper-right corner (just outside frame,
%%       including x-axis label and ticks stick-out if present) 
%% - use \barepanel, \labelxpanel, \labelypanel, \labelxypanel 
%%     to control layout, for example \labelypanel to cut the x labels off
%% - first specify \panelsize width, height in mm;
%%     height=0 or width=0 maintains the frame aspect ratio
%%     larger values give higher resolution (hence the large \textwidth above)
%%     (the example resolves the 18 px/arcsec of the Swedish Solar Telecope)
%% If there are files with different dimensions, repeat \setbb and
%%   choose whether their panel height or width should fit the others
%% Produce bounding-box-cut output of the multi-panel assembly with:
%%   latex cutmultipanel
%%   dvips -E cutmultipanel -o cutresult.eps
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcount\panelwidth \newcount\panelheight 
\newcount\bxmin \newcount\bymin \newcount\bxmax \newcount\bymax
\newcount\tbxmin \newcount\tbymin
\newcount\tpanelwidth \newcount\tpanelheight \newcount\tpdif
\panelwidth=70 \panelheight=70  %% defaults (mm)
\def\panelsize #1,#2;{\panelwidth=#1 \panelheight=#2}  
     %% units MUST be mm
     %% \panelheight=0 or \panelwith=0 maintains frame aspect ratio
\def\setbb #1,#2;#3,#4;#5,#6;{% UNITS: bp (ghostview), delimiters , and ;
  \tbxmin=#1 \tbymin=#2    %% full box (axis titles) lower-left corner
  \bxmin=#3 \bymin=#4      %% bare box (ticks only) lower-left corner
  \bxmax=#5 \bymax=#6}     %% upper-right corner
\def\barepanel #1{%
  \ifnum\panelheight=0 
    \tpdif=\bymax \advance\tpdif by -\bymin
    \multiply \tpdif by \panelwidth
    \tpanelheight=\tpdif
    \tpdif=\bxmax \advance\tpdif by -\bxmin
    \divide \tpanelheight by \tpdif
  \else \tpanelheight=\panelheight \fi
  \ifnum\panelwidth=0 
    \tpdif=\bxmax \advance\tpdif by -\bxmin
    \multiply \tpdif by \panelheight
    \tpanelwidth=\tpdif
    \tpdif=\bymax \advance\tpdif by -\bymin
    \divide \tpanelwidth by \tpdif
  \else \tpanelwidth=\panelwidth \fi
  \epsfig{file=#1,silent=,%
     bbllx=\bxmin bp,bblly=\bymin bp,bburx=\bxmax bp,bbury=\bymax bp,clip=,%
     width=\tpanelwidth mm,height=\tpanelheight mm}}
\def\labelypanel #1{% TeX permits only integer arithmetic, so bp and mm
  \ifnum\panelheight=0 
    \tpdif=\bymax \advance\tpdif by -\bymin
    \multiply \tpdif by \panelwidth
    \tpanelheight=\tpdif
    \tpdif=\bxmax \advance\tpdif by -\bxmin
    \divide \tpanelheight by \tpdif
  \else \tpanelheight=\panelheight \fi
  \ifnum\panelwidth=0 
    \tpdif=\bxmax \advance\tpdif by -\bxmin
    \multiply \tpdif by \panelheight
    \tpanelwidth=\tpdif
    \tpdif=\bymax \advance\tpdif by -\bymin
    \divide \tpanelwidth by \tpdif
  \else \tpanelwidth=\panelwidth \fi
  \tpdif=\bxmax \advance\tpdif by -\tbxmin
  \multiply \tpanelwidth by \tpdif
  \tpdif=\bxmax \advance\tpdif by -\bxmin
  \divide \tpanelwidth by \tpdif
  \epsfig{file=#1,silent=,%
    bbllx=\tbxmin bp,bblly=\bymin bp,bburx=\bxmax bp,bbury=\bymax bp,%
    clip=,width=\tpanelwidth mm,height=\tpanelheight mm}}
\def\labelxpanel #1{%
  \ifnum\panelheight=0 
    \tpdif=\bymax \advance\tpdif by -\bymin
    \multiply \tpdif by \panelwidth
    \tpanelheight=\tpdif
    \tpdif=\bxmax \advance\tpdif by -\bxmin
    \divide \tpanelheight by \tpdif
  \else \tpanelheight=\panelheight \fi
  \ifnum\panelwidth=0 
    \tpdif=\bxmax \advance\tpdif by -\bxmin
    \multiply \tpdif by \panelheight
    \tpanelwidth=\tpdif
    \tpdif=\bymax \advance\tpdif by -\bymin
    \divide \tpanelwidth by \tpdif
  \else \tpanelwidth=\panelwidth \fi
  \tpdif=\bymax \advance\tpdif by -\tbymin
  \multiply \tpanelheight by \tpdif
  \tpdif=\bymax \advance\tpdif by -\bymin
  \divide \tpanelheight by \tpdif
  \epsfig{file=#1,silent=,%
    bbllx=\bxmin bp,bblly=\tbymin bp,bburx=\bxmax bp,bbury=\bymax bp,%
    clip=,width=\tpanelwidth mm,height=\tpanelheight mm}}
\def\labelxypanel #1{%
  \ifnum\panelheight=0 
    \tpdif=\bymax \advance\tpdif by -\bymin
    \multiply \tpdif by \panelwidth
    \tpanelheight=\tpdif
    \tpdif=\bxmax \advance\tpdif by -\bxmin
    \divide \tpanelheight by \tpdif
  \else \tpanelheight=\panelheight \fi
  \ifnum\panelwidth=0 
    \tpdif=\bxmax \advance\tpdif by -\bxmin
    \multiply \tpdif by \panelheight
    \tpanelwidth=\tpdif
    \tpdif=\bymax \advance\tpdif by -\bymin
    \divide \tpanelwidth by \tpdif
  \else \tpanelwidth=\panelwidth \fi
  \tpdif=\bxmax \advance\tpdif by -\tbxmin
  \multiply \tpanelwidth by \tpdif
  \tpdif=\bxmax \advance\tpdif by -\bxmin
  \divide \tpanelwidth by \tpdif 
  \tpdif=\bymax \advance\tpdif by -\tbymin 
  \multiply \tpanelheight by \tpdif
  \tpdif=\bymax \advance\tpdif by -\bymin
  \divide \tpanelheight by \tpdif
  \epsfig{file=#1,silent=,%
    bbllx=\tbxmin bp,bblly=\tbymin bp,bburx=\bxmax bp,bbury=\bymax bp,%
    clip=,width=\tpanelwidth mm,height=\tpanelheight mm}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BEGIN
\begin{document}
\parskip=0ex \parindent=0ex 

%% example (from paper 2015ApJ...808..133R}
\def\figspath{.}
%============================================================================
\begin{figure*}       %% {figure*} for double-column width
\centering 
  \panelsize 50,0;    %% large size for hi-res; height=0 maintains aspect 
  \setbb 19,25; 79,74; 277,278;         %% measured with gv in bp units
  \labelypanel{\figspath/hana.ps}       %% no x-axis labeling
  \hspace{-1.7mm}                       %% adapt horizontal panel spacing
  \barepanel{\figspath/na1.ps}          %% no axis labeling whatsoever
  \hspace{-1.7mm}                          
  \barepanel{\figspath/na2.ps}\\[-0.4ex]   %% adapt vertical panel spacing
  \labelxypanel{\figspath/hamg.ps}         %% both axes labeled  
  \hspace{-1.7mm}
  \labelxpanel{\figspath/mg1.ps}           %% no y-axis labeling
  \hspace{-1.7mm}
  \labelxpanel{\figspath/mg2.ps}           %% no y-axis labeling
\end{figure*}
%============================================================================

\end{document}

