A bachelor's degree in LaTeX, or DSTU 3008-95 in 150 lines

image
Hi all. Recently I also caught a critical milestone in student life — undergraduate thesis. Among the many formal details of this remarkable phenomenon is particularly noticeable is the compliance assessment. No, I understand and strongly support that the standards are necessary, including the standards for the issue of academic text. Just our standards, unlike the Western, is quite idiotic. They don't save any ink, nor paper, they do not simplify the search of the literature on the nomenclature and complicate the reading of the names. Not to mention the fact that the text of the standard was designed and described by people working in the Microsoft Word editor. Again, I don't have anything against Word, it's a powerful system. But a technical text to gain uncomfortable, and the flexibility he many times loses to the immortal creation of Donald Knuth — LaTeX.

So, my thesis started with the fact that I spent 4 hours on a setting of the preamble under the norms of Ukrainian standard DSTU 3008-95. As far as I know, he's almost completely corresponds to the Russian GOST. I know that there are ready decisions (for example, disser), but after a couple of samples prefer to customize every detail yourself. For training. The training was a success — I learned a whole new things about LaTeX, this monster is impossible to learn completely :-)

Under the cut I'll describe the process of setting up each specific part and use them when writing, and different things that simplify the writing of the diploma even more. Immediately warn you: my solution may seem crutches. Somewhere they're not too universal. I know, understand, accept and welcome criticism and suggestions in the comments ;-)

Procurement


Let's start with the workpiece. I assume that you have installed the distro (MiKTeX for Windows or any similar for Linux/Mac) and are set up Cyrillic fonts PsCyr instructions. Don't forget to include extra packages "on the fly" — you'll need them a lot :)

The standard involves writing all of the text in 14 font Times New Roman with single spacing. Last — terminology Microsoft Word) to create its analog in LaTeX, plug in the package extsizes, which adds to the settings of the document class, 14pt, and adjust everything else as written below:
\documentclass[a4paper,14pt,russian]{extreport}

\usepackage{extsizes}
\usepackage{cmap} % for encoding fonts in a pdf
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage{pscyr}

\usepackage{graphicx} % for inserting images
\usepackage{amssymb,amsfonts,amsmath,amsthm} % mathematical additions from AMS
\usepackage{indentfirst} % separate the first line paragraph indent, too
\usepackage[usenames,dvipsnames]{color} % the names of colors
\usepackage{makecell}
\usepackage{ulem} % underline

\linespread{1.3} % half interval
\renewcommand{\rmdefault}{ftm} % Times New Roman
\frenchspacing

\begin{document}

\end{document}
Setting \linespread{1.3} (to increase line spacing to 1.3 times) approximately corresponds to what in the world Word called "half interval". Package cmap includes in the resulting PDF (I use pdfLaTeX) the symbol table, so that the Cyrillic text in PDF becomes possible to copy and look without distorting encodings. Regarding source files, I store them in UTF-8, for your usual setting, change the parameter value at inputenc. The purpose of the other packages, will comment later when I discuss writing a diploma, not a preamble design.

pagination


Numbering of pages should be indicated in the upper right corner. In my case it starts with No. 5, since the first 4 pages is the title, assignment sheet, calendar and other bureaucracy. Form to them was sent as a doc/docx, and they are much easier to print as is, rather than spend the time in the simulation of this design in LaTeX ;)

Connect the package fancyhdr, intended for design header and footer of the page, and poodles it all sorts of defaults. The page is completely clean, except for numbers (\thepage) in the right corner of the header.
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{\thepage
}
\fancyheadoffset{0mm}
\fancyfootoffset{0mm}
\setlength{\headheight}{17pt}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancypagestyle{plain}{
\fancyhf{
}
\rhead{\thepage
}}
\setcounter{page}{5} % to start numbering pages with number 5
it is Worth noting that the first page of the Chapter (chapter) uses the default page style plain. It is necessary also to redefine the terms in fancyhdr that the numbers were stamped on first pages of chapters (see the command \fancypagestyle).

captions and tables


Configure the format of the signatures, which primarily connect the package caption. Because I love the detailed illustrations with several interconnected subparts, connect also the package subcaption. Standard the figure caption is located under the picture and name of the table — above the table. To follow these arrangements you will need (see below), but the package you can tell about this law to make it optimized the allocation of the empty spaces accordingly.
\usepackage{subcaption}
\DeclareCaptionLabelFormat{gostfigure}{picture #2}
\DeclareCaptionLabelFormat{gosttable}{table #2}
\DeclareCaptionLabelSeparator{gost}{~---~}
\captionsetup{labelsep=gost}
\captionsetup[figure]{labelformat=gostfigure}
\captionsetup[table]{labelformat=gosttable}
\renewcommand{\thesubfigure}{\asbuk{subfigure}}Here with the command \DeclareCaptionLabelFormat configures a new custom format, caption, which is then assigned to all figures and tables in the document. Its first argument #1 is standard text label (I chose not to configure it as a separate line, and write clearly without using #1), the second parameter #2 — number of the figure/table.
\DeclareCaptionLabelSeparator sets the separator between the label captions (caption label) and its text that you specify. In our case it is a long dash.

We should also comment on the last line. Since I sometimes share the illustrations on this Subpart, which allows the package subfigure, these subparts need to number. Decided to number them in small letters in order — but in our case it should be Cyrillic letters, not Latin! Cyrillic representation of counters (similar to known representations of arabic, roman, latin, etc.) already implemented in the package babel. It's called, respectively, \asbuk for small Cyrillic letters, and \Asbuk for large.

Give an example of a typical design pattern:
\begin{figure}[ht]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
$$\begin{array}{l}
F \to x \;|\; y \;|\; (S) \\
T \to F \;|\ T \ast F \\
S \to T \;|\; S + T \\
\end{array}$
$
\caption{}
\end{subfigure
} %
\begin{subfigure}[b]{0.6\textwidth}
\centering
\includegraphics[scale=0.7]{parseTree.png}
\caption{}
\end{subfigure
}

\caption{(a) the grammar Production $G$ for the generation of arithmetic expressions;
\label{fig_parsetree}
\end{figure}
table:
\begin{table}[ht]
\caption{Calculation of weight parameters PP}
\label{tab_weight}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline \multirow{2}{*}{$x_i$} & \multicolumn{4}{c|a}{$x_j$} &
\multicolumn{2}{c|a}{First step} & \multicolumn{2}{c|a}{Second step} \\
\cline{2-9} & $X_1$ & $X_2$ & $X_3$ & $X_4$ & $w_i$ &
${K_\text{}}_i$ & $w_i$ & ${K_\text{}}_i$ \\
\hline $X_1$ & 1 & 1 & 1.5 & 1.5 & 5 & 0.31 & 19 & 0.32 \\
\hline $X_2$ & 1 & 1 & 1.5 & 1.5 & 5 & 0.31 & 19 & 0.32 \\
\hline $X_3$ & 0.5 & 0.5 & 1 & 0.5 & 2.5 & 0.16 & 9.25 & 0.16 \\
\hline $X_4$ & 0.5 & 0.5 & 1.5 & 1 & 3.5 & 0.22 & 12.25 & 0.20 \\
\hline \multicolumn{5}{|c|}{total:} & 16 & 1 & 59.5 & 1 \\
\hline
\end{tabular}
\end{table}
it is Worth noting the use of the commands \multirow and \multicolumn to create beautiful tables. They correspond to the HTML <table>: rowspan and colspan, respectively. However, the first requires the use of package multirow.
The result is the design shown below.
For a picture:


For the table:


Headers


Headers according to the standard DSTU 3008-95 is just a song. Or, rather, a mournful doom. All requirements for level headers were designed some creative soul in terms of the Word: skip a line, then two lines, and there is a half interval, and here a double... In the end, after some time spent in trying to come up with a good solution, I had to pick up all constants indents and spacing by hand and sugardaddy them in pixels points. I believe that this is the most disgusting programming style to which I resorted in my entire "career". Although in this case the LaTeX is irrelevant to the programming and does not :)

To format headings use the titlesec. Standard chapters (sections) are written in the center, preceded by the string "Chapter N" and sub-sections and paragraphs are numbered within chapters, and are aligned to the paragraph indent. Everything is typed in bold, the Chapter titles are still in uppercase.

The design of the header is configured by the command \titleformat. It has the following options:
the
    the
  • first — level custom header (e.g. chapter or section);
  • the
  • an optional second — form of the header. Describes global style of placement is whether it will "hang" in the center, printed with the usual bold line before the text, enter the text to be placed in the fields, or something else. Full list of forms is given in the manual on the package, I here use only the display form for registration of a chapter;
  • the
  • the third parameter of the command that are invoked before printing the entire header;
  • the
  • fourth option — making label;
  • the fifth parameter is the distance between label and title text (horizontal or vertical depending on the shape); the

  • the sixth parameter of the commands that are invoked before printing the heading text.
  • the
  • seventh optional commands that are invoked after you print the header text.

These commands allow you to achieve all of the required registration, except for compulsory capitalization of the text of the Chapter title. The command \MakeUppercase works only with one parameter, and cannot be used like \bffamily, to switch the printing format "from forever until the end of the group." Thus, I was able to apply it to the capitalization of header labels (the words "Chapter" or "Appendix"), but the title text had to be printed in all caps on their own. Well, nothing, click the exclusion Button repeatedly turned out to be not so scary :)
\usepackage{titlesec}

\titleformat{\chapter}[display]
{\filcenter}
{\MakeUppercase{\chaptertitlename} \thechapter}
{8pt}
{\bfseries}{}

\titleformat{\section
}
{\normalsize\bfseries}
{\thesection}
{1em}{}

\titleformat{\subsection
}
{\thesubsection}
{1em}{}

% setting vertical and horizontal margins
\titlespacing*{\chapter}{0pt}{-30pt}{8pt}
\titlespacing*{\section}{\parindent}{*4}{*4}
\titlespacing*{\subsection}{\parindent}{*4}{*4}
note the \parindent in the setup of the indentation for the subsections, to make them aligned at the paragraph indent.

And this is how it now looks when you print an ordinary \chapter and \section:


Fields


To set page margins — the most simple of today's challenges:
\usepackage{geometry}
\geometry{left=3cm}
\geometry{right=1.5 cm}
\geometry{top=2.4 cm}
\geometry{bottom=2.4 cm}


Lists


Requirements for the lists in the standard are the following:
the
    the
  • numbered lists at the first level marked as "a), b)"")"... On the second, as "1)", "2)", "3)". Yes, I also don't see a drop of logic.
  • the
  • unordered lists are marked with dashes.

Unfortunately, LaTeX loves to surround environment itemize and enumerate a huge amount of space, creating for them a special mezhabzatsnogo indent. To overcome this vicious habit, you can use package enumitem and ask him the option nolistsep to disable all the extra padding. However, enumitem doesn't know anything about new performance counters asbuk, about which I spoke above, so you must specify it on the command \AddEnumerateCounter. Its third parameter is an example of the wide view (the package will focus on the width when printing). For some reason I (wrongly) think that the widest letter of the Cyrillic alphabet in Times New Roman — this is "m". In any case, the person who creates a numbered list with length from "a" to "m" or below, deserves close attention of health authorities, as for me :)
\usepackage{enumitem}
\makeatletter
\AddEnumerateCounter{\asbuk}{\@asbuk}{m)}
\makeatother
\setlist{nolistsep}
\renewcommand{\labelitemi}{-}
\renewcommand{\labelenumi}{\asbuk{enumi})}
\renewcommand{\labelenumii}{\arabic{enumii})}


table of contents


Table of contents — the second painful stage of the process settings in the preamble. It is necessary to configure the sample, the standard is not very verbose on this matter. Effect of configuration on the model is another bunch of "magic constants" among intervals.
A list of a wide variety of details that should be considered include:
the

    the word "Page" above the column of page numbers; the

  • highlighting of the heads in bold and upper case (and a preliminary "Chapter N");
  • the
  • inclusion in the table of contents of special sections ("Introduction", "List of abbreviations", "Conclusions", "references"...) at the level of ordinary heads, but without the word "Chapter" numbering;
  • the
  • inclusion in the table of contents, subsections and paragraphs, but not sub-items.
  • the
  • and a variety of beautiful alignment.

Fortunately, there is a package tocloft. Copy documentation in the text of this note, I'm not going, it includes countless teams that customize literally each pixel in the table of contents. All these commands — substituting in style "and here is the print between the text of the section or subsection title and the beginning of the dotted line". I use in the preamble to the 9 teams that, in General, configures the appearance of the table of contents:
\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\hspace{0.38\textwidth} \bfseries\MakeUppercase}
\renewcommand{\cftbeforetoctitleskip}{-1em}
\renewcommand{\cftaftertoctitle}{\mbox{}\hfill \\ \mbox{}\hfill{\footnotesize Page.}\vspace{-2.5 em}}
\renewcommand{\cftchapfont}{\normalsize\bfseries \MakeUppercase{\chaptername} }
\renewcommand{\cftsecfont}{\hspace{31pt}}
\renewcommand{\cftsubsecfont}{\hspace{11 PT}}
\renewcommand{\cftbeforechapskip}{1em}
\renewcommand{\cftparskip}{-1mm}
\renewcommand{\cftdotsep}{1}
\setcounter{tocdepth}{2} % to set the depth of the TOC — subsection to, inclusive
These commands set up all necessary things from the above list except one. With special sections will have to do in a special way.

Special sections (abstract, introduction, list of abbreviations, conclusions, list of literature)

These sections are made especially. First, each of them starts on a new page. This is not a problem — the command \newpage knows everyone. Secondly, their title is documented on the page in bold upper case... and is separated from the text by two lines. And finally, to top off this drivel, special sections are in the table of contents at the level of chapters, but not numbered, and chapters are not. Feel like someone had nothing to do with it?

The command \chapter* for obvious reasons not suitable: it has launched chapters are not included in the table of contents. In addition, you need to somehow draw a double line break before the text — not to write \newline manually every time?
We are not looking for easy ways. I decided to create our own section. As it turned out, it is not so difficult.
To determine the section (I called it likechapter) to start is to determine the appropriate subject team. To make centering and capitalization of the name of the section — piece of cake. So I did the command \likechapterheading prints as it is necessary the name of the section.
\newcommand{\empline}{\mbox{}\newline}
\newcommand{\likechapterheading}[1]{
\begin{center
}
\textbf{\MakeUppercase{#1}}
\end{center}
\empline}
section, However, you also need to include in the TOC and level head. And here we have the need to Dodge a little.

Theoretically, the new row is added to the table of contents is done by the command \addcontentsline. She has three parameter:
    the
  1. Type of list to which to add the line. In our case, toc — TOC (table of contents).
  2. the
  3. the Level at which to place the string.
  4. the
  5. Added text string.

With the first and third, everything is clear. But as a second it is impossible to write a "chapter", how helpful tocloft configured by us just above, will print before the line the word "Head". One solution is to go to the end and to determine their own level section.

When LaTeX prints a specific level in the TOC, it calls the internal command \l@XXX, where XXX is the name of the level (chapter, section, etc.). This command has two parameters — the header text and page number. The goal of the team is to print the string directly to the table of contents with dotted line margins and all consideration. If we wish to define your own kind of level, we need to identify a team for its name level. Then the LaTeX during processing of the command \addcontentsline will look for its second parameter, you will find among its definitions of corresponding \l@XXX, where XXX is substituted this with a second parameter, and thereby finishes printing the row in the table of contents.

It remains to determine the command \l@likechapter (incidentally, setting it between dots in the dotted line, as in tocloft), and finish the definition title \likechapter:
\makeatletter
\renewcommand{\@dotsep}{2}
\newcommand{\l@likechapter}[2]{{\bfseries\@dottedtocline{0}{0pt}{0pt}{#1}{#2}}}
\makeatother
\newcommand{\likechapter}[1]{
\likechapterheading{#1
}
\addcontentsline{toc}{likechapter}{\MakeUppercase{#1}}}

Now you can see the result of the works. Here is the beginning of the table of contents:

A special section of the show makes no sense, I guess. It's just bold capitalized text on the page printed with \likechapter{Entry}.

bibliography


When the layout of the references I decided not to use BibTeX, what then is a thousand times regretted. The need to carefully manually set all those slashes, dots, commas and dashes in the description of the next issue of the magazine just kills. But, unfortunately, BibTeX I had not previously enjoyed, and to understand how its design is the desire by the end of the preamble has dried up. Which is a pity.

By the way, I'm sure you have already set up BibTeX files in the already mentioned project disser almost completely solve this problem.

But while here we are considering specifically my preamble. For the layout of the list of references I used old-fashioned and surrounded by thebibliography, and commands \bibitem in its purest form. For a small tweak was necessary to do the following:
\usepackage[square,numbers,sort&compress]{natbib}
\renewcommand{\bibnumfmt}[1]{#1.\hfill} % the numbering of the sources in the list — point
\renewcommand{\bibsection}{\likechapter{List of references}} % title special section
\setlength{\bibsep}{0pt}
Now the title "references" is registered as likechapter, and appropriately placed in the table of contents. Package natbib compresses nicely for the link in something like "[2, 6-9]".

the Count of pages, figures, tables, sources


The standard requires that the abstract of the paper begins with the string "Thesis: 107 p., 14 Fig., 19 tab., 2 applications, 28 sources". Naturally, LaTeX would not be the best system layout of the present, if it was not auto-calculating all these values and insert the desired number in the text command.

Let's start with pages. It is the easiest way: plug-in package lastpage, and the text simply refer to the new that it defines a label LastPage with \pageref*:
\usepackage{lastpage}
% ...
Thesis: \pageref*{LastPage}~S., ...

With figures and tables could to help package totcount, which was written for such purposes to count the number of objects in the document. Unfortunately, as at the moment it has a serious drawback: usually the counters are reset at the end of each Chapter with closed numbering, so that the output in the case of the document type report, not article we receive, not the total number of drawings, but only the number of figures in the last Chapter. The author notified about bug, and while it works, it was necessary to find a workaround.

The recipe was found on open spaces of StackOverflow. We define for every object type a private counter, then this counter will write to the aux file (after compilation, the command \AtEndDocument). The next time you compile it will take from a file, and a certain us team fills in the text. Thus, after two runs of pdfLaTeX, we get the text with the correct counter value.
\newcounter{totfigures}
\newcounter{to Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

A Bunch Of MODx Revolution + LiveStreet

Monitoring PostgreSQL with Zabbix

PostgreSQL load testing using JMeter, Yandex.Tank and Overload