\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{bgj}

\newif\if@igo
\@igotrue
\DeclareOption{noigo}{\@igofalse}
\DeclareOption{igo}{\@igotrue}

\ExecuteOptions{a5paper,10pt}
\ProcessOptions

\LoadClass{article}

% BGJ144-preamble - Xmas 2007 - try to make it self documenting
% clean up a new version at start of each journal 
% 144 starts as 143 starts as 142 starts as 141 left off
%% EXCEPT THE LAST LINE
% Complex bits like the Sokolov support get parameterised and commented out.

\usepackage{palatino}
% options helvet   Times Arial palatino (138/139/140)
% TO DO measure page count impacts

% LANGUAGES - e acute in decor .. \'e 
% warning re Pal Balogh see macro and more notes at end of bgj-nnn.sty - used in 140

\usepackage{color}
\usepackage{float}
\usepackage[left=12mm,right=12mm,top=1.2cm,bottom=1.3cm,paper=a5paper,nohead,foot=0.5cm]{geometry}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{caption}
\usepackage{titletoc}
\usepackage{wrapfig}
\usepackage{eurosym}
\usepackage{xspace}

% see info in {bgj-nnn.sty}
\usepackage{ragged2e}

\usepackage{ifthen}
\if@igo
\usepackage{igo}
\fi
% NB: igo sets a few things it shouldn't really - so BGJ-nnn.sty has to clean up after it.


% BGJ140-v6 contains all the Fonts and this include file to use the
% Andrei Sokolov Counting article the way that he had typeset it.
%   why input - not usepackage ???
%   \input ./gooemacs.tex
% this may only be needed with AS
%\usepackage{epsf}
\usepackage{epstopdf}

% \usepackage{bgj}
% try with fixup  -- more needed ?
% \usepackage{bgj-2-igo-fix-2-as} was used in 140
% well it seems to be able to set the Andrei Sokolov text
% when it all got mucked up again found that RaggedRight is the problem

% so start 144 which is same as 143 
%%% \usepackage{bgj-144} - put this in main file



% BGJ - 144 -  2008
% Start as for 142 and 143
%
%  COMMENT CHANGES HERE .. difference at the end 
%
%
% try my own - upfront of these - see fontsize.tex
% Andrew Jobbings Took an axe to most of this ..
% but caused the default fontsize to grow somewhat .. so only 44 lines on sample page instead of 49 
% Curiously reinstating the igo like normalsize gets back to 50 lines...

%\renewcommand{\small}{\fontsize{9}{9}\selectfont }
%\renewcommand{\normalsize}{\fontsize{10}{10}\selectfont }
%\renewcommand{\large}{\fontsize{12}{12}\selectfont }

%% Page numbers in ?? 9.5pt ?

%% Now  try the modified versions from igo.sty - or it doesn't work
%%% TRY putting this back in - 29 mar 07  -- gets us back to 50 lines on the Font size page ..
\renewcommand\normalsize{%
    \@setfontsize\normalsize\@xpt\@xpt
    \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
    \abovedisplayshortskip \z@ \@plus3\p@
    \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
    \belowdisplayskip \abovedisplayskip
    \let\@listi\@listI
    \def\stonesize{\igo@fonts{9}}%
}

%\renewcommand\small{%
%    \@setfontsize\small\@ixpt{9}%
%    \abovedisplayskip 8.5\p@ \@plus3\p@ \@minus4\p@
%    \abovedisplayshortskip \z@ \@plus2\p@
%    \belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
%    \def\@listi{\leftmargin\leftmargini
%        \topsep 4\p@ \@plus2\p@ \@minus2\p@
%        \parsep 2\p@ \@plus\p@ \@minus\p@
%        \itemsep \parsep}%
%    \belowdisplayskip \abovedisplayskip
%    \def\stonesize{\igo@fonts{8}}%
%}
% end of modified versions from igo.sty

% Allow for blank lines

\newcommand{\blankline}{\vspace{\baselineskip}\noindent}

% For the uninitiated - makeatletter affects the way symbols inside macro's
% are interpretted - only need to understand if doing clever things
\makeatletter \renewcommand\section{\@startsection {section}{1}{0pt}
  {-\baselineskip} {0.2\baselineskip} {\bfseries \scshape \LARGE}
  }\makeatother

\newcommand{\webfont}[1]{\small{\texttt{#1}}\normalsize}
% try even smaller font on 142
\newcommand{\sml}{\fontsize{8}{8}\selectfont}
\newcommand{\smallerwebfont}[1]{\texttt{\sml{#1}}\normalsize}
% % % could use package URL instead  <<<<<<<<<<< % TO DO experiment
% above has habit of breaking the line ...
% maybe because of the complicated igo normalsize macro

% these weren't used in 140 - will try them out in 141
\newfloat{photo}{H}{phot}

\DeclareCaptionStyle{photo}{justification=raggedright,font={sf,small}}

\captionsetup[photo]{style=photo}

\captionsetup{font={small,sf},belowskip={1pt plus 0.5pt minus
    0.5pt},aboveskip={2pt plus 1pt minus 1pt}}

\newfloat{gofigure}{H}{gofig} \floatname{gofigure}{Figure}

\newfloat{godiag}{H}{godiag} \floatname{godiag}{Diagram}

\newcommand{\gocomment}[4][]{\ifthenelse{\isodd{#2}}{\mbox{\blackstone[#2]}}{\mbox{\whitestone[#2]}}
#1 \textit{#3:} #4}

\newcommand{\anoncomment}[3][]{\ifthenelse{\isodd{#2}}{\mbox{\blackstone[#2]}}{\mbox{\whitestone[#2]}}
#1 #3}

\newcommand{\officialtitle}[1]{\textsc{#1}}

\newcommand{\gogloss}[1]{\textsc{\textbf{#1}}}

% END 140 unused set


% BJC TWEAK - reduce from 12 to 10 pt
\makeatletter
\renewcommand\subsection{\@startsection
{subsection}{2}{0mm} {\baselineskip} {0.1\baselineskip}
{\fontsize{10}{10}\bfseries}}
\makeatother

% Reduce fontsizes here ... too
% play with the interclub spacing 2mm wrecked everything
\newcommand{\clubtitle}[1]{\vspace*{1mm}\textsc{\textbf{#1}}}
\newcommand{\alsoclubtitle}[1]{\textsc{\textbf{#1}}}
%use first param as alternate name .. conditional it to x .. idea for future
%% \newcommand{\clubsect}[2][x]{\vspace*{1mm}\textsc{\textbf{#2}}  \if ? <> x then (also callled #1)\newline }


\setlength{\parindent}{0cm}
\setlength{\columnsep}{10pt}
%\setlength{\intextsep}{3pt plus 2pt minus 2pt}
\setlength{\parskip}{4pt plus 2pt minus 2pt}

% aha - expect this is what put vertical line in when I went to multicols 2
% \setlength{\columnseprule}{0.5pt}

% see titletoc package for options here ..
% http://www.mackichan.com/index.html?techtalk/655.htm~mainFrame suggested
% \titlecontents{chapter}[0pt]{\addvspace{1pc}\itshape}{\contentsmargin{0pt}
% \bfseries\makebox[0pt][r]{\large\thecontentslabel\enspace}\large}
% {\contentsmargin{0pt}\large}{\hfill\contentspage}[\addvspace{.5pc}]


% 140 used this simple
% \titlecontents{section} [0pt] {\addvspace{-3pt}\bfseries}
% {\thecontentslabel} {\thecontentslabel} {\contentspage}


% 141 Project - Improve Contents Page
\titlecontents{section} [0pt] {\addvspace{0pt}}
% 1) addvspace change from -3 to +3 spaced it out far too much - try 0
% 2) comment out the clause completely ... causes runaway
% 3) remove the \bfseries
{\thecontentslabel} {\thecontentslabel}
% don't know why this it repeated ? but suffered runaway when I commented out one of them
{\contentspage}


% Dec 17 2006 - experiment with ragged right everywhere to reduce hyphenations
% See http://www.tex.ac.uk/cgi-bin/texfaq2html?label=ragright and link to hyphen suppress
%  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \RaggedRight
% use this as and when

% these seem to work too - in combination with raggedRight - reduce hyphenations a lot ..
\setlength{\lefthyphenmin}{4}
\setlength{\righthyphenmin}{4}
%% BUT AJ chopped them out - But I want them back in !!!!!

\newcommand{\bgjarticle}[3] {%
\section*{{#1}}\large \textbf{#2}\hfill\normalsize{\sffamily #3}%
\addcontentsline{toc}{section}{\textsc {#1} \hfill
% \textsc - uppercase it - looks better as J Diamond suggested authors in normal
%  .. not all capitalised
{#2}}%
\setcounter{godiag}{0}%
\setcounter{gofigure}{0}%
}

% NEW late 141 for Letters page(s)
\newcommand{\bgjletters}{%
\section*{{Letters to the Editor}}%
\addcontentsline{toc}{section}{\textsc {Letters}\hfill}%
}

% NEW late 144 for Letters to president page(s)
\newcommand{\bgjPresletter}{%
\section*{{Letters to the President}}%
\addcontentsline{toc}{section}{\textsc {Letters}\hfill}%
}

\newcommand{\bgjsignletter}[2] {%
\textbf{#1}\newline\normalsize{\hspace*{5mm}\webfont{#2}}% \textbf{#1}\newline\normalsize{\sffamily #2}%
}



% From Andrei Sokolov - Jan - 07
\newcommand{\extravskip}{\vspace*{12pt}}
\newcommand{\smallvskip}{\vspace{4pt}}
%%% But notice standard ideas like \medskip that AJ pointed out.


% BJC for the TA Korea puzzles in 140 - just give it a number or letter
% set up an igo GoBan, list of black and white stones - then render with this..
\newcommand{\GoProblem}[1] {
\begin{center}
\framebox[5cm]{
\begin{minipage}{4cm} {
\begin{center}
\large\textbf{\textsc{Problem #1}} \shortstack{\vspace*{12pt}\\
\showgoban\\Black to play}
\end{center}
}
\end{minipage}
}
\end{center}

\vspace*{3mm}

}
%% the vspace is new - to keep it off the bottom of the page 

% pre-140 \renewcommand{\GoProblem}[1] {\large\textbf{\textsc{Problem #1}} }

% remove all the bgj140 kludging for now ..
% \input{Andrei-Sokolov-SGF2TEX-Support}



%% AJ idea
\newenvironment{GameAnalysis}
	{\setlength{\RaggedRightRightskip}{0pt plus 4.5em}%
	\RaggedRight
	\setlength{\parskip}{2pt plus 1pt minus 1pt}%
	\setlength{\abovecaptionskip}{0 pt}}
	{}

\newenvironment{Advert}
	{\setlength{\parskip}{2pt plus 1pt minus 1pt}%
	}
	{}

%% Trademarks etc
\newcommand{\fridgego}{fridge\textbf{go}}

%% references to Letters in Diagrams
\newcommand{\DLabA}{\texttt{A}}
\newcommand{\DLabB}{\texttt{B}}

%%% PlayerNames
%% 142 \newcommand{\PalB}{P\'al Balogh}
%% 142 \newcommand{\PalBsp}{P\'al Balogh }
%% 142 TA says he never uses it - 140 it was Nick Wedd's review comment..
%%% 143 remove \newcommand{\PalB}{Pal Balogh}
%%% \newcommand{\PalBsp}{Pal Balogh }
%% nb  the space version should really be done with closing \ like \PalB\
% Nick (140) suggests a dangerous precedent
% If print one Hungarian name with its accents, should do so for all Hungarian names.
% Csaba Mero will be more difficult.  His e has an acute accent, which will be
% easy enough, but his o has a double acute accent, which may be more difficult.
%% it merging with the following text .. but I was in a rush at the time of 140 
%%%  SUGGEST That this section be broken out into a New file PlayerNames.tex and that included...
% \newcommand{Mullerumlaut}{M\ddot{u}ller}
\newcommand{\Mullerumlaut}{M\"uller}
%
\newcommand{\ADiner}{Alexander Dinerchtein}
%

%%% Currency symbols - lots of ways to do these in Latex - see package eurosym
%% \def\Pound{{\rm \char'44}} this produced a $
%%%%%   EASIER to USE \pounds  .. needs a recheck .. and \pounds{}


% Avoid ugly hyphenations ..  here is one idea 5000 and 2000  .. so play a bit
% but it would redo whole journal at last moment
\hyphenpenalty=5000
\tolerance=1000
% and it does affect UK NEWS Drastically .. but seems a good idea for future
% from  http://dcwww.camd.dtu.dk/~schiotz/comp/LatexTips/LatexTips.html#nohyphen
%
% try just the bad words in AGARules - this would be cool - ERROR ``not a letter''
%     \hyphenation{seriously,tournaments}
% I really want a local way of stopping ugly hyphens

% Another problem is when we want a hyphen to be non-breaking as in Ki-in
% various sugestions include {-}  and mbox{hyphen-word}
\newcommand{\kiin}{\mbox{Ki-in}\xspace}  
%   http://www.tex.ac.uk/cgi-bin/texfaq2html?label=xspace is a solution
% must avoid it swallowing following space
\newcommand{\NK}{Nihon \kiin}

% Okay, this might be a bit extreme, but I like to do this sort of
% thing in case I change my mind about conventions later! --- EB
\newcommand{\kyu}[1]{#1k}
\newcommand{\dan}[1]{#1d}
\newcommand{\pro}[1]{#1p}

% enumerate and itemize environments are, by default, indented too
% far to be any use, I think. This moves them slightly to the left --- EB
\setlength{\leftmargini}{16pt}

