Skip to content
Snippets Groups Projects
HYthesisML.cls 32.1 KiB
Newer Older
Heikki Ahonen's avatar
Heikki Ahonen committed
%%
%% This is file `HYthesisML.cls'
%%
%% 
%% HYthesisML.cls supports the creation of BSc and MSc theses,
%% seminar papers, and other reports at the Department of Computer Science at the University of Helsinki. An eventual motivation
%% is to spread the style to uses at other departments as well, by
%% making localisations easy. 
%%
%% The style class history:
%% * modifications Veli Mäkinen, 2019
%% * modifications Tomi Männistö, 2019
%% * template for BSc and MSc by Niko Mäkitalo and Lea Kutvonen, 2019
%% * tktltiki style and bibliography style by Anton Puolakka, 2002
%% * inspired by that, a version by Department of Physics, 2017
%% * template and style updates by Veli Mäkinen, 2018
%% * technical renewal and enhancement by Lea Kutvonen, 2018
%%   to be extended to similar looking word template as well
%%
%% Changes between policies in 2002 and 2018:
%% * cover pages changed (also from Physics)
%% * use of new (and old) curricula terms in titlepages and
%%   in abstracts (level of theses, study programme and subject domain
%%   within it, supervisor and examiner data for the needs of physical
%%   sciences)
%% * utf8 as default
%% * mnemonic abbreviations in bibliographies have been abandoned,
%%   instead choise between numberic and apacite styles 
%%   are made optional
%% * nomenclature shall be fixed soon (for Physics)
%% * technical internal changes has been necessary for gaining 
%%   stability of service for users: many packages have become obsolete
%%   or changed a lot (very loose expectations have been given for
%%   the required packages to ease the use on individual, separately
%%   administered computers, watching out merely for major package
%%   behaviour changes causing mismatches)
%% * translator.sty was adopted to support dictionaries on terms
%%   related to curricula and scientific area, allowing each
%%   department to provide their own key phrases
%%
%%
%%% This work may be distributed and/or modified under the
  % conditions of the LaTeX Project Public License, either version 1.3
  % of this license or (at your option) any later version.
  % The latest version of this license is in
  %   http://www.latex-project.org/lppl.txt
  % and version 1.3 or later is part of all distributions of LaTeX
  % version 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[2000/06/01]
\ProvidesClass{HYthesisML}[2018/10/01 v1.0 Document class for BSc and MSc theses in Computer Sciences of University of Helsinki]
%
\newif\if@finnish%
\newif\if@swedish%
\newif\if@english%
\@finnishfalse\@swedishfalse\@englishfalse%
\newif\if@latin\@latinfalse%
% computer science specific content starts
\newif\if@cs% 
\newif\if@csm%
\newif\if@tkt%
\newif\if@tktl%
\newif\if@dsm%
\newif\if@censored%
\newif\if@seminar%
\@csfalse\@csmfalse\@tktfalse%
\@tktlfalse\@dsmfalse\@censoredfalse%
\@seminarfalse%
% computer science specific content ends
%
\DeclareOption{finnish}{\@finnishtrue}
\DeclareOption{swedish}{\@swedishtrue}
\DeclareOption{english}{\@englishtrue}
                                          % requires extra user commds
\DeclareOption{latin}{\@latintrue}        % Latin0 vs utf8

% line content starts
\DeclareOption{sw-line}{\def\track{sw-line}}
\DeclareOption{alko-line}{\def\track{alko-line}}
\DeclareOption{nodes-line}{\def\track{nodes-line}}
\DeclareOption{bio-line}{\def\track{bio-line}}
\DeclareOption{sw-line-2017}{\def\track{sw-line-2017}}
\DeclareOption{alko-line-2017}{\def\track{alko-line-2017}}
\DeclareOption{nodes-line-2017}{\def\track{nodes-line-2017}}
\DeclareOption{bio-line-2017}{\def\track{bio-line-2017}}
\DeclareOption{sw-track-2018}{\def\track{sw-track-2018}}
\DeclareOption{alko-track-2018}{\def\track{alko-track-2018}}
\DeclareOption{nodes-track-2018}{\def\track{nodes-track-2018}}
\DeclareOption{software-track-2020}{\def\track{software-track-2020}}
\DeclareOption{algorithms-track-2020}{\def\track{algorithms-track-2020}}
\DeclareOption{networking-track-2020}{\def\track{networking-track-2020}}

% line content ends

% programme specific content starts
\DeclareOption{cs}{\@cstrue}
\DeclareOption{csm}{\@csmtrue}
\DeclareOption{tkt}{\@tkttrue}
\DeclareOption{tktl}{\@tktltrue}
\DeclareOption{dsm}{\@dsmtrue}
\DeclareOption{censored}{\@censoredtrue}
\DeclareOption{seminar}{\@seminartrue}
% programme specific content ends

\newif\if@oneside
\newif\if@twoside
\@onesidefalse
\@twosidetrue
\newif\if@defaulttypesize
\@defaulttypesizetrue

\DeclareOption{oneside}{\@onesidetrue\@twosidefalse}
\DeclareOption{twoside}{\@twosidetrue\@onesidefalse}
\DeclareOption{10pt}{
  \@defaulttypesizefalse
  \PassOptionsToClass{10pt}{report}}
\DeclareOption{11pt}{
  \@defaulttypesizefalse
  \PassOptionsToClass{11pt}{report}}
\DeclareOption{12pt}{
  \@defaulttypesizefalse
  \PassOptionsToClass{12pt}{report}}
\DeclareOption{a4paper}{
  \PassOptionsToClass{a4paper}{report}}
\if@defaulttypesize
  \PassOptionsToClass{12pt}{report}
\fi
%TM- changed a4page->a4paper \PassOptionsToClass{openright,twoside,a4page}{report}
%TM: Moved to ...main.tex
%\PassOptionsToClass{openright,twoside,a4paper}{report}
% In theses, open new chapters only at right page.
% For other types of documents, may ask "openany" in document.

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
% Report class takes care of any errors in options.
\ProcessOptions\relax

\LoadClass{report}[2000/05/19]

\RequirePackage[T1]{fontenc}

Heikki Ahonen's avatar
Heikki Ahonen committed
\RequirePackage{latexsym}[1998/08/17 v2.2e Standard LaTeX package (lasy symbols)]

\if@latin
\RequirePackage[latin9]{inputenc}[2015/03/17 v1.2c The inputenc package]
\else
\RequirePackage[utf8]{inputenc}[2015/03/17 v1.2c v1.3 The inputenc package]
\fi


\if@finnish
  \RequirePackage[english,swedish,main=finnish]{babel}[2001/03/01 v3.7h The Babel package]
  \selectlanguage{finnish}
  %\selectbiblanguage{finnish}
\else
  \if@english
    \RequirePackage[swedish,finnish,main=english]{babel}[2001/03/01 v3.7h The Babel package]
    \selectlanguage{english}
    %\setbiblanguage{english} 
   \else
    \if@swedish
      \RequirePackage[finnish,english,main=swedish]{babel}[2001/03/01 v3.7h The Babel package]
      \selectlanguage{swedish}
      %\setbiblanguage{swedish}
    \fi
  \fi
% viimeinen osa pois
\fi

%\RequirePackage{geometry}
%\if@oneside
%    \geometry{oneside,vscale=0.8, includefoot, vmarginratio={1:1}, hmarginratio={3:2}}
%\else
%    \geometry{twoside,vscale=0.8, includefoot, vmarginratio={1:1}, hmarginratio={3:2}}
%\fi
%\savegeometry{defaultgeometry}

\RequirePackage{geometry}[1999/10/07 v2.2 Page Geometry]
%TM: changed the geometry to the same as Data Science template
% \newcommand{\defaultsettings}{%
%   \if@twoside
%     \geometry{top=2.5cm, left=2.8cm, right=3.2cm,
%               textwidth=15cm, textheight=23cm,
%               headheight=0.5cm, headsep=0.5cm}%
%   \else
%     \geometry{top=2.5cm, left=3.5cm, right=2.5cm,
%               textwidth=15cm, textheight=23cm,
%               headheight=0.5cm, headsep=0.5cm}%
%   \fi
% }
\newcommand{\defaultsettings}{%
  \if@twoside
    \geometry{bindingoffset=0.5cm,top=2.5cm, left=2.5cm, right=2.5cm,
              %TM- removed, overspecification
              %textwidth=16cm, 
              textheight=23cm,
              headheight=0.5cm, headsep=0.5cm}%
  \else
    \geometry{top=2.5cm, left=2.5cm, right=2.5cm,
              textwidth=16cm, textheight=24cm,
              headheight=0.5cm, headsep=0.5cm}%
  \fi
}
%TM: added the following as the use of the just defined macro was missing
\defaultsettings

% Default marginratio is 1:1 for oneside 2:3 for twoside pages
% Default vscale=0.7, hscale=0.7
% Bindingoffset would increase the smaller margin (inner) and decrease the textwidth,
% therefore, same bindingoffset effect is here obtained by swapping the margin 
% Better fill rate for Finnish and more appropriate footnote management acquired by
% balancing hscale+includefoot options

                          % This is necessary: utilised (as 
                          % replacementof obsolete packages)
\RequirePackage{etoolbox} % for careful patching of internal macros
                          % if constructs
                          % hooks for \atbegindocument, \atenddocument 
\patchcmd{\chapter}{plain}{empty}{}{}
                          % removes page numbers from p1 of chapter
\RequirePackage{lastpage}
\RequirePackage{nomencl}
\RequirePackage{emptypage}
\RequirePackage{perpage}
%
                           % This is the area of expected changes
\RequirePackage{titlesec}  % as new form packages arrive
\RequirePackage{titletoc}
\RequirePackage{titleps}
\RequirePackage[page,toc,title,titletoc,header]{appendix}
\patchcmd{\@chap@pppage}{\thispagestyle{plain}}{\thispagestyle{empty}}{}{}
\RequirePackage[subfigure]{tocloft}
\noappendicestocpagenum
\titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter}{0.5em}{}
\titlespacing*{\chapter}{0pt}{-20pt}{30pt}


\RequirePackage{xstring}


%%%%  keep these good charm lines! 
\setcounter{page}{1}
\setcounter{chapter}{0}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex}
\renewcommand{\normalsize}{\fontsize{12}{15}\selectfont}
\pagenumbering{arabic}
\pagestyle{myheadings}
\setcounter{chapter}{0}
\pagenumbering{roman}
\setcounter{chapter}{0}
% This is a bottleneck: if abstract of report style pushes in
% anything extra, the output document and error messages
% get garbled and uninterpretable. There is a simple abstract
% text page (centered) left, but all document control structures 
% are lost.
\RequirePackage[runin]{abstract}[2001/06/11]
\renewcommand{\abstractname}{}    % clear the title
\renewcommand{\absnamepos}{empty} % originally center
\renewcommand{\@bsrunintitle}{}
%%%%  end of charm

% Computer science: use 1-1.5 as a normal for 1-column documents.
\newcommand{\onehalfspacing}{%
  \ifcase\@ptsize\relax % 10pt
    \renewcommand{\baselinestretch}{1.25}%
  \or % 11pt
    \renewcommand{\baselinestretch}{1.213}%
  \or % 12pt
    \renewcommand{\baselinestretch}{1.241}%
  \fi
  \normalsize
}
\newcommand{\doublespacing}{
  \ifcase\@ptsize\relax % 10pt
    \renewcommand{\baselinestretch}{1.667}
  \or % 11pt
    \renewcommand{\baselinestretch}{1.618}
  \or % 12pt
    \renewcommand{\baselinestretch}{1.655}
  \fi
  \normalsize
}
\newcommand{\singlespacing}{%
  \renewcommand{\baselinestretch}{1.0}%
  \normalsize
}

\newcommand{\mytableofcontents}{%
% next page with text should be odd
%TM:  \newpage
  \cleardoublepage
 
  \tableofcontents
%TM:  \newpage
  \cleardoublepage
  \pagenumbering{arabic}
%  \if@emptyfirstpagenumber
    \thispagestyle{empty}
%  \fi
}

%%%% trilanguage handling
\RequirePackage{translator}  % see the 3 files of translator-UHCSthesis
\usedictionary{translator-UHCSthesis-coverpage-dictionary}

%%%%%% Define commands for filling abstract
%%%%% For form texts
\newcommand{\oppiaine}[1]{\gdef\@oppiaine{#1}} % abstract template
%%%%% Degree elements
%Defined elsewhere --report
%\newcommand{\author}[1]{\gdef\@author{#1}}
%\newcommand{\title}[1]{\gdef\@title{#1}}

\newcommand{\warnText}[1]{
{\color{red}{#1}}
}


%These determined through options or commands
%\newcommand{\level}[1]{\gdef\@level{#1}}
%\newcommand{\programme}[1]{\gdef\@programme{#1}}
%\newcommand{\subject}[1]{\gdef\subject{#1}}
%\subject{}
\newcommand{\subject}{}
\newcommand{\getSubject}{
    \department
}

\newcommand{\seminar}[1]{\gdef\@seminar{#1}}
%%%%% Document details
\newcommand{\depositeplace}{\translate{library}}
\newcommand{\pp}{\translate{pp}}
\newcommand{\app}{\translate{appendices}}
\newcommand{\appno}{\translate{appendice pages}}
\newcommand{\ccs}[1]{\gdef\@ccs{#1}}
\ccs{ACM Computing Classification System (CCS)}
% From document itself
\newcommand{\classification}[1]{\gdef\@classification{#1}}
\classification{\space Compulsory ACM classification missing}
\newcommand{\keywords}[1]{\gdef\@keywords{#1}}
\keywords{}
\newcommand{\additionalinformation}[1]{\gdef\@additionalinformation{#1}}
%\additionalinformation{}
%%%%% Evaluation related elements
\newcommand{\supervisorslabel}{\translate{supervisors}}
\newcommand{\examinerlabel}{\translate{examiner}}
% From document
\newcommand{\supervisors}[1]{\gdef\@supervisors{#1}}
\newcommand{\examiners}[1]{\gdef\@examiners{#1}}

%%%%% Organisation elements
\newcommand{\uh}{\translate{uh}}
\newcommand{\address}{\translate{address}}
\newcommand{\eaddress}{\translate{eaddress}}
\newcommand{\ytiedot}{\translate{ytiedot}}
\newcommand{\helsinki}{\translate{helsinki}}
\newcommand{\faculty}{\translate{faculty}}

%%% Process degree specific info

\if@tkt
    \newcommand{\level}%
      {\translate{tkt-bsc-level}}
    \newcommand{\programme}%
      {\translate{tkt-programme}}
    \newcommand{\department}%
      {\translate{department2018}}
    \renewcommand{\oppiaine}{{Koulutusohjelma --- Utbildningsprogram  --- Study programme}}
    \renewcommand{\getSubject}{\programme}
	\providecommand{\track}{}
Heikki Ahonen's avatar
Heikki Ahonen committed
\fi
\if@tktl
    \newcommand{\level}%
      {\translate{tkt-bsc-level}}
    \newcommand{\programme}%
      {\translate{tktl-programme}}
    \newcommand{\department}%
      {\translate{department2017}}
    % expected document to set \subject{}
    \renewcommand{\oppiaine}%
       {{Koulutusohjelma --- Utbildningsprogram  --- Study programme}}
    % VM: poistin "oppiaineeseen laitos" lisäämällä allaolevan
    \renewcommand{\department}{\programme}
    \renewcommand{\getSubject}{\programme}
	\providecommand{\track}{}
Heikki Ahonen's avatar
Heikki Ahonen committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
\fi
\if@cs
    \renewcommand\subject{\translate{\track}}
    \newcommand{\level}{\translate{msc-level-2018}}
    \newcommand{\programme}{\translate{cs-programme}}
    \newcommand{\department}{\translate{department2017}}
    \renewcommand{\oppiaine}{{Koulutusohjelma --- Utbildningsprogram  --- Study programme}}
    % VM: poistin "oppiaineeseen laitos" lisäämällä allaolevan
    \renewcommand{\department}{\programme}
    %\renewcommand{\getSubject}{\programme}
    %VM: adding stydy line / study track to additional information
    %\renewcommand{\additionalinformation}{\subject}
%    \renewcommand{\getSubject}{
%        \ifx\subject\empty
%            \warnText{!! You must set subject !!}
%        \else
%            \department:\\ \subject
%        \fi
%    }
\fi
\if@csm
    \renewcommand\subject{\translate{\track}}
    \newcommand{\level}{\translate{msc-level-2020}}
    \newcommand{\programme}{\translate{csm-programme}}
    \newcommand{\department}{\translate{department2018}}
%    expected document to set \subject{}
     \renewcommand{\oppiaine}{{Koulutusohjelma --- Utbildningsprogram  --- Study programme}}
     \renewcommand{\department}{\programme}
    %VM: adding stydy line / study track to additional information
    %\renewcommand\additionalinformation{\subject}
    %TM: commented out -- no more study lines printed
    % \renewcommand{\getSubject}{
    %     \ifx\subject\empty
    %         \warnText{!! You must set subject !!}
    %     \else
    %         \department:\\ \subject
    %     \fi
    % }
\fi

%% actual parameters from document

%% Look of the reports
\usepackage{lmodern} 
\usepackage{textcomp} 
\usepackage[pdftex]{color, graphicx} % For pdf output and jpg/png graphics
\usepackage{epsfig}
\usepackage{subfigure} 
\usepackage{tikz}            % For making vector graphics (hard to learn but powerful)
\usepackage{amsmath, amssymb} % For better math
\usepackage[footnotesize,bf]{caption}  % For more control over figure captions
\usepackage{blindtext}

\newcommand{\frontmatter}{
    \setcounter{page}{1}
    \pagenumbering{arabic}
}


\newcommand{\mainmatter}{
    \cleardoublepage 
    \thispagestyle{empty}
    \pagenumbering{arabic}
    \setcounter{page}{1}
}

\newcommand{\backmatter}{%
    \addtocounter{numberofappendixes}{1}
    \setcounter{numberofpages}{\value{page}} 
    
    \addtocontents{toc}{\cftpagenumbersoff{chapter}}
    \cleardoublepage

    \titleformat{\chapter}{\large\bfseries}{\chaptertitlename\space\thechapter\newline}{0.5em}{\setcounter{page}{1}\pagenumbering{roman}\markboth{\chaptertitlename\space\thechapter}{\chaptertitlename \space\thechapter}\label{Appendix.\thechapter}\thispagestyle{empty}}
%    \titleformat{\chapter}{\Huge\bfseries}{\chaptertitlename\space\thechapter\newline}{0.5em}{\setcounter{page}{1}\pagenumbering{arabic}\markboth{}{}\label{Appendix.\thechapter}}
    \thispagestyle{empty}
}



% Additions and changes for document key terms. 
% These address elements required for computer science.
\addto\captionsenglish{%
\renewcommand{\bibname}{References}%
\renewcommand{\refname}{References}%
\renewcommand{\nomname}{List of acronyms}%
}
\addto\captionsfinnish{%
\renewcommand{\bibname}{L\"ahteet}%
\renewcommand{\refname}{L\"ahteet}%
\renewcommand{\appendixname}{Liite}%
\renewcommand{\appendixpagename}{Liitteet}%
\renewcommand{\appendixtocname}{Liitteet}%
%\renewcommand{\appendicestocname}{Liitteet}%
%\renewcommand{\appendicespagename}{Liitteet}%
\renewcommand{\enclname}{Liite}%
\renewcommand{\nomname}{Lyhenteet}%
%\renewcommand{\enclpagename}{Liite}%
%\renewcommand{\encltocname}{Liite}%
}
\addto\captionsswedish{%
\renewcommand{\bibname}{Bibliografi}%
\renewcommand{\refname}{Bibliografi}%
\renewcommand{\appendixname}{Bilaga}%
\renewcommand{\appendixtocname}{Bilagor}%
\renewcommand{\appendixpagename}{Bilagor}%
%\renewcommand{\appendicespagename}{Bilagor}%
%\renewcommand{\appendicestocname}{Bilagor}%
\renewcommand{\enclname}{Bilaga}%
\renewcommand{\nomname}{List av akronymer}%
}
\def\dateswedish{\def\today{\number\day.\number\month.\number\year}}
\def\datefinnish{%
  \def\today{\number\day.\number\month.\number\year}}
\def\division{\char'057}

%--------------------------------------------------------------------------
% Nomenclature: titles and unit space
%\makenomenclature
%\newcommand{\nomunit}[1]{%
%\renewcommand{\nomentryend}{\hspace*{\fill}#1}}

%\newcommand{\mynomenclature}{%
%\ifnum0\pdffilesize{\jobname.nls}>0
%	\printnomenclature
%	\addcontentsline{toc}{chapter}{\nomname}
%	\markboth{\nomname}{}
%	\cleardoublepage
%\fi
%\pagenumbering{arabic}
%}


\renewcommand*{\thefootnote}{\fnsymbol{footnote}} %footnote symbols for one page only
\MakePerPage{footnote}
%----------------------------
\AtEndPreamble{%

% user command to ask for the value
\providecommand{\recallcounter}[1]{\@ifundefined{stored@#1}{Rerun or fix for number of pages info in abstract}{\csname stored@#1\endcsname}}   
% used at the aux

\providecommand{\restorecounter}[2]{\expandafter\gdef\csname stored@#1\endcsname{#2}}

\providecommand\recalltext[1]{\if{mytext@#1}\@nameuse{mytext@#1}\fi}
}% end of end preamble


\newcommand{\numberofpagesinformation}[1]{
    \gdef\@numberofpagesinformation{#1}
}
\numberofpagesinformation{}
    
\newcommand{\pagesInformation}[1]{
    \gdef\@pagesInformation{#1}
}
\pagesInformation{}

%%%%%% Appendices %%%%%%%

\newcounter{appendixPagesCounter}
    \setcounter{appendixPagesCounter}{0}%

    \let\oldappendix\appendix
    \renewcommand{\appendix}[1]{
        \addtocounter{appendixPagesCounter}{\value{page}}%
        \typeout{***appendixPagesCounter \theappendixPagesCounter}


%TM: This one set the last page of each appendix to 1, which kinda is not what one wants 
%TM:-        \setcounter{page}{1}%
        \chapter{#1}
    }   


\renewcommand{\appendices}{%
    \setcounter{page}{-1}%
%  \setcounter{appendix}{1}%
%  \newpage
%  %\pagestyle{empty}
%  \pagestyle{myheadings}
%  \markright{}
    \oldappendix
%  \addtocontents{toc}{\protect \contentsline {section}{\enclname}{}}
%  \setcounter{page}{0}
}



\AtBeginDocument{

    \newcounter{selfdefined}
    \newcounter{numberofpages}
    \newcounter{numberofappendixes}
    \newcounter{numberofappendixpages}

    \newcommand{\numberofpagesinfo}[1]{\gdef\@numberofpagesinfo{#1}}
    \newcommand{\numberofappendixesinfo}[1]{\gdef\@numberofappendixesinfo{#1}}
    \newcommand{\iffirstrun}{\@ifundefined{notfirstrun}}


    \iffirstrun{%

      \setcounter{selfdefined}{0}
      \setcounter{numberofpages}{0}
      \setcounter{numberofappendixes}{0}
      \setcounter{numberofappendixpages}{0}

      \numberofpagesinfo{}
      \numberofappendixesinfo{}
    }{%
   
         
      \ifnumcomp{\value{selfdefined}}{=}{0}{%
         % hidden setcounter cmds from aux for all counters above here
         
         \ifnumcomp{\value{numberofappendixes}}{=}{0}%  
         % view together with same split in \atenddocument
         {%
         }{% appendixes exist, backmatter takes care of mainmatter pages
            \appendixinfo{,\space\arabic{numberofappendixes}\space\@app\space(\arabic{numberofappendixpages}\space\@appno)}
         } 
    }{ % author defined cases handled by separate user command below
    % write to aux all texts (note: lang spesific)
    % to become available as author command elements
    % on the second pdflatex run
    
    % only used as author command  
    \providecommand{\setnumberofpagesinformation}[1]{
        \addtocounter{selfdefined}{1}
        \numberofpagesinformation{#1}
    }

  }
}
}


\newcounter{appendixpage}


\AtEndDocument{%

    \iffirstrun{

    }{
        \addtocounter{appendixPagesCounter}{\value{page}}%
        \typeout{***AED Number of Appendices \theappendixPagesCounter}
        \immediate\write\@auxout{\string\gdef\string\appendixCount{\theappendixPagesCounter}}

        \typeout{***AED Number of pages \thenumberofpages \pp}
        \immediate\write\@auxout{\string\gdef\string\pagesCount{\thenumberofpages}}
    }


    \immediate\write\@auxout{\string\gdef\string\notfirstrun{}}

        
    \ifnumcomp{\value{numberofappendixes}}{=}{0}{%      
        \setcounter{numberofpages}{\value{page}}
        \numberofpagesinfo{\arabic{numberofpages}\space\@pp}
    }{%
        \setcounter{numberofappendixes}{\value{chapter}}
        \addtocounter{numberofappendixpages}{\value{page}}
    }
}



\newcommand{\getPageInfo}{%
    \@ifundefined{pagesCount} {
        \warnText{!! Run three times to appear !!}
     } {
        \ifnumcomp{\appendixCount}{>}{0}{%
            \pagesCount\space\pp,\space\appendixCount\space\appno
        }{
            \pagesCount\space\pp
        }
    }
}


%---------------------------------------------

% GENERATE TITLE PAGE

%%%%%%%%%%%%%%      Cover pages
%% define first the inside of cover page, i.e. the second page
\newcommand{\innerpage}{%
\makeatletter
\setcounter{page}{-998}
\label{in}
\thispagestyle{empty}
\if@censored 
 {
    \par
    {\bf\supervisorslabel}\par
%TM: parindent only indents the first line -> use \leftskip within {}
%    {\addtolength{\parindent}{2em} 
    {\leftskip=2em
     \@supervisors
  %  \addtolength{\parindent}{-2em}}
     \par
    }
    
    \par
    {\bf\examinerlabel}\par
    {\leftskip=2em
     \@examiners
     \par
    }
}
\fi

\vspace{4.0cm}
    \par
    {\bf \ytiedot}\par
    \hfill\par
    %TM: Using \leftskip here, too. Removed \indent from translation files after \newline
    {\leftskip=2em
     \address
     \par
    }
    \hfill\par
    {\leftskip=2em
     \eaddress
     \par
    }
%TM: 
\vfill

%TM: commented out as it seems \makeatother should not used in .cls files...
%\makeatother
\thispagestyle{empty}
} 

%%%% actual cover page, triggers the backside of the leaf printed too

\renewcommand{\maketitle}{%
%TM: removed, as seems not needed !?
%\enlargethispage{0.7in}
\hypersetup{pageanchor=true}
\setcounter{page}{-999}
\label{title}
\if@seminar
 \level{}
\fi


\onehalfspacing

\begin{center}
\includegraphics[width=5cm]{HY-logo-ml.png}

%\makeatletter
\begin{large}
\level

\programme

% VM: Removed study line = study track from title page
%\if@csm
    %TM- skip subject (=study line) 
%\else
%    {\subject}
%\fi

\end{large}

\vspace{1.7cm}

\begin{LARGE}
{\bf \@title}
\end{LARGE} 

\vspace{2cm}

\begin{large}
\@author
\end{large}

\vspace{14pt}

\begin{large}
\today

\vspace{2.5cm}
%{\bf \@seminar}

\vspace*{\fill}

{\rm\sc
    \faculty

    \uh
}
\end{large}
%\makeatother
\end{center}

\thispagestyle{empty}\newpage
\innerpage
}


%------------------------------------------------------------------------

\newsavebox{\@abstract}

%TM: modified to make abstract bit tightier
\newenvironment{@summary}{
    \abst@small %TM:+
    \begin{lrbox}{\@abstract}
    \begin{minipage}[t][12cm]{5.7in} %TM: fixed the minipage height (=summary+ACM classif to 12cm); adjust if layout changes
    \setlength{\parskip}{2ex}
}
{ 
    \vfill %TM: works only here, if the minipage height is known, thus fixed above
    {\bf \@ccs}
    %TM:- \par\space\par
    \abst@small \@classification
    \end{minipage}
    \end{lrbox}
%TM this needed moving after changes to abstract page 
%    \put(75, 560){\mbox{\usebox{\@abstract}}}
    \put(22, 450){\mbox{\usebox{\@abstract}}}

%TM just used for debugging:
%    \put(75, 560){\framebox{\usebox{\@abstract}}}
}

\def\abst@small{\fontsize{10}{10}\selectfont}
\def\abst@tiny{\fontsize{6}{7}\selectfont}


% Making the boxed abtract page, in all languages used
\renewenvironment{abstract}%
{
\iflanguage{finnish}{\label{page.abstract.finnish}}{\iflanguage{swedish}{\label{page.abstract.swedish}}{\iflanguage{english}{\label{page.abstract.english}}{\label{page.abstract.other}}}}
%TM:- commented following line out due to multiple times defined label warning 
% \label{page.abstract.}
\thispagestyle{empty}\newpage

% would be nice to know how to change the page geometry within these environment so that the picture would fit within the text area -- now only page length can be easily changed, as some other stuff does not have effect at this point. 
% \newgeometry{bindingoffset=0cm, top=0cm, left=0cm, right=0cm, bottom=0cm,
%               %TM- removed, overspecification
%               %textwidth=16cm, 
%               %textheight=29cm,
%               headheight=0cm, headsep=0cm}
%or these            
% \setlength{\topsep}{100pt}%
% \setlength{\leftmargin}{0pt}%
% \setlength{\rightmargin}{0pt}%
%This works in making the page longer
\enlargethispage{24pt} %this is just enough for the current box size

%TM +++ 
\begin{picture}(400,678)(0,0) %pic width is too small to get rid of the overfull hbox warning; just drawing wider; this seems to be no problem for latex page creation, as it only needs to fit the picture as defined, not to care about someone drawing outside the picture.

%Put the content texts there
\put(5, 634){\makebox(200, 8)[l]{\abst@small \faculty}}
\put(233, 634){\makebox(200, 8)[l]{\abst@small \getSubject}}  

\put(5,  601){\makebox(100, 8)[l]{\abst@small \@author}}
\put(5,  564)%
    {\parbox{450pt}{\abst@small \@title}}
 
\put(5,  527)%
    {\parbox{450pt}{\abst@small \@supervisors}}
 
\put(5, 490){\makebox(100, 8)[l]{\abst@small \level}}
\put(160, 490){\makebox(100, 8)[l]{\abst@small \today}}
\put(301, 490){\makebox(100, 8)[l]{\abst@small \getPageInfo}}

\put(5, 85) {\makebox(100, 8)[l]{\abst@small \@keywords}}
\put(5, 55) {\makebox(100, 8)[l]{\abst@small \depositeplace}}
\put(5, 25) {\makebox(100, 8)[l]{\abst@small \@additionalinformation}}
\begin{@summary}
 }{
\end{@summary}

%the bix surrounding box
\put(0,0){\framebox(462,666){}}

%the text on top, outside the big box
\put(1,670){\makebox(461,10)[l]{\abst@small\sc HELSINGIN YLIOPISTO -- HELSINGFORS UNIVERSITET -- UNIVERSITY OF HELSINKI}}

%then the heading texts for the small boxes and lines 
\put(5,657){\makebox(150,6)[l]{\abst@tiny Tiedekunta --- Fakultet --- Faculty}}
\put(231,629){\line(0,1){37}} % pystyviiva
\put(236,657){\makebox(100,5)[l]{\abst@tiny \oppiaine}}
\put(0,629){\line(1,0){462}} 

\put(5,620){\makebox(100,5)[l]{\abst@tiny Tekij\"a --- F\"orfattare --- Author}}
\put(0,592){\line(1,0){462}}

\put(5,583){\makebox(100,5)[l]{\abst@tiny Ty\"on nimi --- Arbetets titel --- Title}}
\put(0,555){\line(1,0){462}}

\put(5,546){\makebox(100,5)[l]{\abst@tiny Ohjaajat --- Handledare --- Supervisors}}
\put(0,518){\line(1,0){462}}

\put(5,509){\makebox(100,5)[l]{\abst@tiny Ty\"on laji --- Arbetets art --- Level}}
\put(154,481){\line(0,1){37}} % pystyviiva
\put(159,509){\makebox(100,5)[l]{\abst@tiny Aika --- Datum --- Month and year }}
\put(297,481){\line(0,1){37}} % pystyviiva
\put(303,509){\makebox(100,5)[l] {\abst@tiny Sivum\"a\"ar\"a --- Sidoantal ---    Number of pages}}

\put(5,472){\makebox(100,5)[l]{\abst@tiny Tiivistelm\"a --- Referat --- Abstract}}
\put(0,481){\line(1,0){462}}

\put(0,0){\line(1,0){462}}
\put(0,50){\line(1,0){462}}
\put(0,80){\line(1,0){462}}
\put(0,110){\line(1,0){462}}
\put(3,101){\makebox(100,5)[l]{\abst@tiny Avainsanat --- Nyckelord --- Keywords}}
\put(1.5,71){\makebox(100,5)[l]{ \abst@tiny S\"ailytyspaikka --- F\"orvaringsst\"alle --- Where deposited}}
\put(5,41){\makebox(100,5)[l]{\abst@tiny Muita tietoja --- \"ovriga uppgifter --- Additional information}}

\end{picture}

}



% %%% TM: ---- OlD way of making the abstract page.
%>>>
% \renewenvironment{abstract}%
% {
% \iflanguage{finnish}{\label{page.abstract.finnish}}{\iflanguage{swedish}{\label{page.abstract.swedish}}{\iflanguage{english}{\label{page.abstract.english}}{\label{page.abstract.other}}}}
% %TM:- commented following line out due to multiple times defined label warning 
% % \label{page.abstract.}
% \thispagestyle{empty}
% %TM: +++ just for cheking the page print area corners
% %+ \hfill +

% %TM: expect the page to have been changed before 
% %\newpage
% %\clearpage
% %\cleardoublepage

% %TM +++ 
% %\begin{picture}(595,842)(50,-90)% The last two are positioning the abstract on the page; TM: that was the here previously, definging an whole page and a picture with an origin way out of the page. (This is the way it was earlier)
% \begin{picture}(400,650)(53,130) %hack: too small pic size (to avoid overfull hbox), moved up to compensate, sad. And  positioning the abstract on the page to compensate for the bottom left corner coordinates used below!?!?
% %\begin{picture}(462,678)(53,110) % Somehow these values sound like closer to proper pic size, but may need changing page geometry or something to work out well. 
% % The framing box (way below) could be in placed in (0,0), but there is an offset in use, so need to compensate for that above (instead of recalculating and changing all the values below;)
% % \put(0,0){\framebox(461,666){}} %try this to see where it goes;)

% \put(58,  744){\makebox(200, 8)[l]{\abst@small \faculty}}

% %TM: changed use of getSubject to be like the others
% %\put(286, 744){
% %    \ifx\subject\empty
% %        \parbox{450pt}{\abst@small \getSubject}        
% %    \else
% %       \parbox[b]{450pt}{\abst@small \getSubject}
% %    \fi
% %
% \put(286, 744){\makebox(200, 8)[l]{\abst@small \getSubject}}   

% \put(58,  711){\makebox(100, 8)[l]{\abst@small \@author}}
% \put(58,  674)%
%     {\parbox{450pt}{\abst@small \@title}}
 
% \put(58,  637)%
%     {\parbox{450pt}{\abst@small \@supervisors}}
 
% \put(58, 600){\makebox(100, 8)[l]{\abst@small \level}}
% \put(213, 600){\makebox(100, 8)[l]{\abst@small \today}}
% \put(354, 600){\makebox(100, 8)[l]{\abst@small \getPageInfo}}

% \put(58, 195) {\makebox(100, 8)[l]{\abst@small \@keywords}}
% \put(58, 165) {\makebox(100, 8)[l]{\abst@small \depositeplace}}
% \put(58, 135) {\makebox(100, 8)[l]{\abst@small \@additionalinformation}}
% \begin{@summary}
%  }{
% \end{@summary}
% \put(53,110){\framebox(462,666){}} % laatikko





% %\put(54,780){\makebox(100,8)[l]{\abst@small\sc HELSINGIN YLIOPISTO -- HELSINGFORS UNIVERSITET -- UNIVERSITY OF HELSINKI}}
% \put(54,780){\makebox(461,10)[l]{\abst@small\sc HELSINGIN YLIOPISTO -- HELSINGFORS UNIVERSITET -- UNIVERSITY OF HELSINKI}}

% \put(58,767){\makebox(150,6)[l]{\abst@tiny Tiedekunta --- Fakultet --- Faculty}}
% \put(284,739){\line(0,1){37}} % pystyviiva
% \put(289,767){\makebox(100,5)[l]{\abst@tiny \oppiaine}}
% \put(53,739){\line(1,0){462}} 

% \put(58,730){\makebox(100,5)[l]{\abst@tiny Tekij\"a --- F\"orfattare --- Author}}
% \put(53,702){\line(1,0){462}}

% \put(58,693){\makebox(100,5)[l]{\abst@tiny Ty\"on nimi --- Arbetets titel --- Title}}
% \put(53,665){\line(1,0){462}}

% \put(58,656){\makebox(100,5)[l]{\abst@tiny Ohjaajat --- Handledare --- Supervisors}}
% \put(53,628){\line(1,0){462}}

% \put(58,619){\makebox(100,5)[l]{\abst@tiny Ty\"on laji --- Arbetets art --- Level}}
% \put(207,591){\line(0,1){37}} % pystyviiva
% \put(212,619){\makebox(100,5)[l]{\abst@tiny Aika --- Datum --- Month and year }}
% \put(350,591){\line(0,1){37}} % pystyviiva
% \put(356,619){\makebox(100,5)[l] {\abst@tiny Sivum\"a\"ar\"a --- Sidoantal ---    Number of pages}}

% \put(58,582){\makebox(100,5)[l]{\abst@tiny Tiivistelm\"a --- Referat --- Abstract}}
% \put(53,591){\line(1,0){462}}

% \put(53,110){\line(1,0){462}}
% \put(53,160){\line(1,0){462}}
% \put(53,190){\line(1,0){462}}
% \put(53,220){\line(1,0){462}}
% \put(58,211){\makebox(100,5)[l]{\abst@tiny Avainsanat --- Nyckelord --- Keywords}}