#  /====================================================================\
# | sv support for LaTeXML                                              |
# | Generated by texscan --stub --base=article.cls svjour2.cls           |
#  >====================================================================<
# | Released to public domain.                                           |
# | Bruce Miller <bruce.miller@nist.gov>                                 |
# | http://dlmf.nist.gov/LaTeXML/                                        |
#  \====================================================================/

use strict;
use LaTeXML::Package;

# Only if option natbib!
RequirePackage('natbib');

#======================================================================
# Frontmatter
DefMacro('\titlerunning',Tokens());
DefMacro('\titrun',Tokens());
DefMacro('\subtitle{}', '\@add@frontmatter{ltx:subtitle}{#1}');

DefMacro('\authorrunning',Tokens());
DefMacro('\authrun',Tokens());

DefConstructor('\@institute{}',"<ltx:contact role='institute'>#1</ltx:contact>", bounded=>1);
DefMacro('\institute{}','\@add@to@frontmatter{ltx:creator}{\@institute{#1}}');
DefMacro('\inst{}','\@add@to@frontmatter{ltx:creator}{\@institute{#1}}');

DefConstructor('\@email{}',"^ <ltx:contact role='email'>#1</ltx:contact>");
DefMacro('\email Semiverbatim', '\@add@to@frontmatter{ltx:creator}{\@email{#1}}');
DefConstructor('\@mail{}',"^ <ltx:contact role='address'>#1</ltx:contact>");
DefMacro('\mail{}', '\@add@to@frontmatter{ltx:creator}{\@mail{#1}}');

# What's all this for?
Let(T_CS('\at'),T_CS('\and'));
Let(T_CS('\iand'),T_CS('\and'));
Let(T_CS('\nand'),T_CS('\and'));
Let(T_CS('\lastand'),T_CS('\and'));

DefMacro('\keywords{}',  '\@add@frontmatter{ltx:keywords}{#1}');
DefMacro('\subclass{}',  '\@add@frontmatter{ltx:classification}[scheme=MSC]{#1}');
DefMacro('\CRclass{}',   '\@add@frontmatter{ltx:classification}[scheme=CR]{#1}');
DefMacro('\ESM{}',       '\@add@frontmatter{ltx:note}[role=supplemental]{#1}');
DefMacro('\PACS{}',      '\@add@frontmatter{ltx:classification}[scheme=pacs]{#1}');
DefMacro('\headnote{}',  '\@add@frontmatter{ltx:note}{#1}');
DefMacro('\dedication{}','\@add@frontmatter{ltx:contact}[role=dedicatory]{#1}');
DefMacro('\offprints{}', '\@add@frontmatter{ltx:note}[role=offprints]{#1}');
DefMacro('\journalname{}','\@add@frontmatter{ltx:note}[role=journal]{#1}');
DefMacro('\papertype{}',  '\@add@frontmatter{ltx:classification}[scheme=papertype]{#1}');

Let(T_CS('\journalopt'),T_CS('\@empty'));

DefMacro('\makereferee',Tokens());

DefConstructor('\acknowledgements',"<ltx:acknowledgements>");
DefConstructor('\acknowledgement', "<ltx:acknowledgements>");
DefConstructor('\endacknowledgements',"</ltx:acknowledgements>");
DefConstructor('\endacknowledgement', "</ltx:acknowledgements>");
Tag("ltx:acknowledgements", autoClose=>1);

DefEnvironment('{noteadd}','<ltx:note>#body</ltx:note>');

Let(T_CS('\orithanks'),T_CS('\thanks'));
DefMacro('\runheadhook',Tokens());
DefMacro('\svlanginfo',Tokens());
DefMacro('\makeheadbox',Tokens()); # Should be covered by frontmatter/maketitle
DefMacro('\authdepth','2');
DefMacro('\authorfont','\bfseries');
DefMacro('\stripauthor',Tokens()); # ?
DefRegister('\instindent'=>Dimension(0));
DefMacro('\combirun',Tokens());
DefMacro('\combirunning{}',Tokens());

DefMacro('\validfor',Tokens());
DefMacro('\ClassInfoNoLine{}{}',Tokens());
DefMacro('\ProcessRunnHead',Tokens());
DefMacro('\fnmsep',Tokens());	# ?
DefMacro('\institutename',Tokens());	# ?
#======================================================================
DefMacro('\nocaption{}',Tokens());
DefMacro('\sidecaption {}',Tokens());

DefMacro('\capstrut',Tokens());
DefMacro('\captionstyle','\normalfont\small');
DefRegister('\figcapgap'=>Dimension('3pt'));
DefRegister('\tabcapgap'=>Dimension('5.5pt'));
DefRegister('\figgap'=>Dimension('1cc'));

DefMacro('\tableheadseprule','\hrule');
DefMacro('\floatlegendstyle','\bfseries');
DefMacro('\leftlegendglue',Tokens());

DefPrimitive('\normalthmheadings', sub { AssignValue('thm@swap' => 'N'); });
DefPrimitive('\reversethmheadings',sub { AssignValue('thm@swap' => 'S'); });
DefRegister('\spthmsep'=>Dimension('5pt'));

# \spnewtheorem*{env}[numberedlike]{caption}[within]{capfont}{bodyfont}
# NOTE: Can I use latex's \newtheoremstyle, or do I need to copy & adapt it?
# Seems to be the same as \newtheoremstyle, but with additonal capfont & bodyfont
DefMacro('\spnewtheorem OptionalMatch:* {}[]{}[] {}{}', sub {
  my ($stomach, $flag, $thmset, $otherthmset, $text, $reset, $capfont, $bodyfont) = @_;
  $thmset = ToString($thmset);
  $otherthmset = $otherthmset && ToString($otherthmset);
  $text   = undef unless $text->unlist;
  $reset  = $reset ? ToString($reset) : undef;

  my $counter = $otherthmset || $thmset;
  my $swap    = LookupValue('thm@swap') eq 'S';

  if(!$otherthmset){
    NewCounter($counter, $reset,
	       idprefix => "Thm$counter");
    DefMacroI(T_CS("\\the$counter"),undef,
	      "\\csname the$reset\\endcsname\\\@thmcountersep\\arabic{$counter}",
	      scope=>'global')
      if $reset; }

  DefEnvironment("{$thmset} OptionalUndigested",
		 "<ltx:theorem xml:id='#id' refnum='#refnum'>"
		 . "<ltx:title>#title</ltx:title>"
		 .  "#body"
		 ."</ltx:theorem>",

		 afterDigestBegin=> sub {
		   my($stomach,$whatsit)=@_;
		   my $note = $whatsit->getArg(1);
		   my $refnum = $whatsit->getProperty('refnum');
		   my($a,$b) = ($swap ? ($refnum,$text) : ($text,$refnum));
		   my @toks=(T_BEGIN,$capfont->unlist);
		   push(@toks,
			($a ? $a->unlist :()),
			($a && $b ? (T_SPACE):()),
			($b ? $b->unlist : ()));
		   if($note){
		     push(@toks,T_SPACE,T_OTHER('(')) if $text;
		     push(@toks,$note->unlist);
		     push(@toks,T_OTHER(')')) if $text; }
		   push(@toks,T_CS('\the'),T_CS('\thm@headpunct'),T_END);
		   $whatsit->setProperties(title=>Digest(Tokens(@toks)));

		   Digest($bodyfont); },
		 ($counter 
		  ? (properties => sub {
		       ($flag ? RefStepID($counter) : RefStepCounter($counter));})
		  :()),
		 scope => 'global');
});

Let(T_CS('\spdefaulttheorem'),T_CS('\spnewtheoerem'));

RawTeX(<<'EOTeX');
\spnewtheorem{theorem}{Theorem}[section]{\bfseries}{\itshape}
\spnewtheorem*{claim}{Claim}{\itshape}{\rmfamily}
\spnewtheorem*{proof}{Proof}{\itshape}{\rmfamily}
\spnewtheorem{case}{Case}{\itshape}{\rmfamily}
\spnewtheorem{conjecture}{Conjecture}{\itshape}{\rmfamily}
\spnewtheorem{corollary}{Corollary}{\bfseries}{\itshape}
\spnewtheorem{definition}{Definition}{\bfseries}{\rmfamily}
\spnewtheorem{example}{Example}{\itshape}{\rmfamily}
\spnewtheorem{exercise}{Exercise}{\bfseries}{\rmfamily}
\spnewtheorem{lemma}{Lemma}{\bfseries}{\itshape}
\spnewtheorem{note}{Note}{\itshape}{\rmfamily}
\spnewtheorem{problem}{Problem}{\bfseries}{\rmfamily}
\spnewtheorem{property}{Property}{\itshape}{\rmfamily}
\spnewtheorem{proposition}{Proposition}{\bfseries}{\itshape}
\spnewtheorem{question}{Question}{\itshape}{\rmfamily}
\spnewtheorem{solution}{Solution}{\bfseries}{\rmfamily}
\spnewtheorem{remark}{Remark}{\itshape}{\rmfamily}
EOTeX

DefEnvironment('{theopargself*}','#body'); # ?
DefEnvironment('{theopargself}','#body');  # ?

DefEnvironment('{translation}{}',"<ltx:quote class='translation' lang='#1'>#body</ltx:quote>");

#======================================================================
DefConstructor('\qed',
	       "?#isMath(<ltx:XMTok role='PUNCT'>\x{220E}</ltx:XMTok>)(\x{220E})");
Let(T_CS('\smartqed'),   T_CS('\qed'));
Let(T_CS('\squareforqed'),   T_CS('\qed'));

DefMacro('\tens{}','\ensuremath{\mathsf{#1}}');

#======================================================================
# Random text
DefMacro('\CRclassname','\textbf{CR Subject Classification}');
DefMacro('\ESMname','\textbf{Electronic Supplementary Material}');
DefMacro('\PACSname','\textbf{PACS}');
DefMacro('\ackname','Acknowledgements');
DefMacro('\andname','and');
DefMacro('\chaptername','Chapter');
DefMacro('\claimname','Claim');
DefMacro('\conjecturename','Conjecture');
DefMacro('\contriblistname','List of Contributors');
DefMacro('\corollaryname','Corollary');
DefMacro('\definitionname','Definition');
DefMacro('\emailname','E-mail');
DefMacro('\examplename','Example');
DefMacro('\exercisename','Exercise');
DefMacro('\keywordname','\textbf{Keywords}');
DefMacro('\lastandname',', and');
DefMacro('\lemmaname','Lemma');
DefMacro('\mailname','\textit{Correspondence}');
DefMacro('\noteaddname','Note added in proof');
DefMacro('\notename','Note');
DefMacro('\problemname','Problem');
DefMacro('\proofname','Proof');
DefMacro('\propertyname','Property');
DefMacro('\questionname','Question');
DefMacro('\remarkname','Remark');
DefMacro('\seename','see');
DefMacro('\solutionname','Solution');
DefMacro('\subclassname','\textbf{Mathematics Subject Classification (2000)');
DefMacro('\theoremname','Theorem');
DefMacro('\etal','et al.');
DefMacro('\notused','~');

#======================================================================
DefRegister('\aftertext'=>Dimension('5pt'));
DefRegister('\betweenumberspace'=>Dimension('3.33pt'));
DefRegister('\headerboxheight'=>Dimension('180pt'));
DefRegister('\headlineindent'=>Dimension('1.166cm'));

DefMacro('\runinend',Tokens());
DefMacro('\floatcounterend',Tokens());
DefMacro('\sectcounterend',Tokens());

# These should do 1 or 2 depending on twocolumn mode!
DefMacro('\columncase','\makeatletter\twocolteset');
DefMacro('\twocoltest{}{}','#1\makeatother');

NewCounter('lastpage');
DefMacro('\getlastpagenumber',Tokens());
DefMacro('\islastpageeven',Tokens());

DefMacro('\makesectrule',Tokens());
DefMacro('\makesectruleori',Tokens());
DefMacro('\nosectrule',Tokens());
DefMacro('\restoresectrule',Tokens());
DefMacro('\nothanksmarks',Tokens());
DefMacro('\setitemindent{}',Tokens());
DefMacro('\setitemitemindent{}',Tokens());
DefMacro('\thisbottomragged',Tokens());

DefMacro('\rubric',Tokens());
DefRegister('\rubricwidth'=>Dimension('0pt'));
DefMacro('\strich',Tokens());
DefRegister('\logodepth'=>Dimension('1.2cm'));
DefMacro('\lastevenhead',Tokens());
#======================================================================
1;
