Introduction
There are several popular tools for formatting texts, such as Microsoft Office, Libre Office, etc. In general, these are convenient editors that attract with their simplicity, but when it comes to a large number of formulas with automatic numbering, figures, schemes and tables, the design turns into another task. It is possible that the situation with the design of formulas has changed at the moment, but in the past, MathType for a set of formulas was considered a certain standard. In Microsoft Office and Libre Office, you can work on the basis of styles and get some automation in numbering, styling, but this is often neglected.
As an alternative, there has always been TeX, LaTeX, XeTeX, XeLaTeX, etc. The style of text formatting in these systems is unusual compared to visual editors. For those who are not familiar, the text is created in the form of special markup. From the nearest analog it is similar to creating HTML pages. In order to get a readable document with a visual design, you need to compile it. Compilation usually takes place as a chain of command calls. The most popular output is a PDF document.
We’re going to consider XeLaTeX, because it’s easy to choose different fonts and has Unicode support. In some places, XeLaTeX will always be mentioned, even though the functionality originally existed in TeX or LaTeX.
All examples from the article are taken mainly from the ready-made document class and sample on GitHub.
Setting up the environment
Let’s take a look at installing the distribution package and choosing an editor to create documents.
Installing the Distribution
There are two options:
-
Install everything locally.
-
Work in cloud services. For example, in OverLeaf.
Let’s consider the option of local installation, since it is more universal and will allow you to understand the process of obtaining the final PDF document from the markup text. Locally, there will be no time limits for compiling a document, installing additional packages, etc. Cloud services may have different restrictions depending on the tariff.
There are two popular distributions:
Up-to-date list of available distributions for different platforms. At the time of the thesis, the author used and still uses MikTex under Windows. I had a little experience with TeX Live under Linux. Also, there were no particular problems.
Once installed, you should have the following command available:
xelatex -version
Installing the Editor
Markup can be typed in any text editor, but it is much more convenient, especially without a lot of experience, to have a more specialized editor for XeLaTeX. There are several options here as well:
Additionally, you can look for extensions and plugins for your favorite editor. Additionally, it will be useful at the start Character recognition service. In it, you can draw a symbol and get a command to play it.
It is also possible to pre-set automatic file formatting for XeLaTeX. For example, the extension for VS Code automatically invokes this program when the format command is called.
Creating the First Document
Once everything is set up, you can proceed to the first example. Let’s create a document hello_xelatex.tex
and compile it:
xelatex -halt-on-error -enable-installer ./hello_xelatex.tex
hello_xelatex.tex
\documentclass[12pt, oneside]{extarticle}
\usepackage{polyglossia}
\setdefaultlanguage[indentfirst=true,forceheadingpunctuation=false]{russian}
\setotherlanguages{english}
\IfFontExistsTF{Times New Roman}
{\setmainfont{Times New Roman}
\newfontfamily\cyrillicfont{Times New Roman}[Script=Cyrillic]}
{\setmainfont[Script=Cyrillic]{FreeSerif}}
\IfFontExistsTF{Courier New}
{\setmonofont{Courier New}
\newfontfamily\cyrillicfonttt{Courier New}[Script=Cyrillic]
}
{\setmonofont[Script=Cyrillic]{FreeMono}}
\IfFontExistsTF{Arial}
{\setsansfont{Arial}
\newfontfamily\cyrillicfontsf{Arial}[Script=Cyrillic]
}
{\setsansfont[Script=Cyrillic]{FreeSans}}
\title{Привет XeLaTeX}
\author{Автор}
\date{\today}
\begin{document}
\maketitle
\section{Введение}
\subsection{Сгенерированный текст языковой моделью (пунктуация и орфография оригинальная)}
Latex - это система компьютерной вёрстки, разработанная для создания технической и научной документации, а также других видов печатной продукции. Она широко используется в академических кругах, научно-исследовательских институтах и промышленных предприятиях для создания различных документов, включая научные статьи, учебники, технические отчёты и т.д. Latex предоставляет набор инструментов и команд для форматирования текста, составления математических формул, графиков, таблиц и других элементов документа. Одной из главных особенностей Latex является его расширяемость и возможность создания собственных команд и стилей.
\end{document}
In the markup of the document, an external package is connected polyglossia
, setting languages, some options and choosing fonts. It is assumed that one of the fonts specified in the text is available in the system. For example, Times New Roman or FreeSerif. If this is not the case, then you need to either install the appropriate fonts or change them to those that are installed in the system. Usually, there are requirements for fonts in advance, so you need to choose the one that is required. As a rule, Times New Roman is quite popular for obtaining a thesis.
As a result, you will get a PDF document as shown in Fig. below (image can be enlarged), which you can open and view. Instead of explicitly invoking a command xelatex
Can be used latexmk
. This is a kind of analogue make
. When writing a complex document, a single run may not be enough to get all the information you need to complete the document. latexmk
simplifies the process.
The document will show basic formatting, some features, and issues. For example, although clearly nowhere are hyphenations fromfishing is not in the document, they are. This is all due to the fact that polyglossia
Knows some information about how to hyphenate. On the other hand, there is a portion of the text that falls outside the acceptable scope. Such places will be displayed in the logs as Overfull
. There are many ways to deal with team. For example, insert \sloppy
after the paragraph. The main problem of everyone who starts using XeLaTeX is how to make the necessary formatting of various elements and change something.
There are several options here:
-
Use the appropriate
documentclass
with the right settings. -
Use external packages that allow you to customize various aspects of formatting.
-
Override, augment built-in commands.
The syntax for defining the class of a document and what is commonly used in text markup is slightly different. For example, the command to use a package in document markup would be \usepackage{...}
, in the document class, it will be \RequirePackage{...}
. In the text of the article, there will be teams from different places, but logically they are the same. The following table summarizes the command mappings that are used in the article:
Command in Markup Text |
A Command in a Document Class |
---|---|
|
|
|
|
Formatting settings
If the formatting rules are known in advance and you need to create a lot of documents according to them, then the easiest way to do this is your own documentclass
and put all the basic formatting settings there. Only the main points will be covered. More detailed information can be found in the documentation of the respective packages. Learn more about creating custom document classes can be read in the Overleaf materials.
Let’s start from the beginning. Let’s skip the formulas because. There are a lot of examples on this topic on the Internet.
Font and size of the main text, indentation in the text
How to set up different fonts was at the beginning of this example. Let’s say the size requirements are such that it should be 14pt. This is done simply by passing the argument to the base class on which the class to be created will be based:
\LoadClass[14pt, oneside]{extarticle}
If you need an arbitrary text size. For example, 24pt or 36pt, this will be a problem because only certain sizes are allowed in the extarticle options. At the time, it was not possible to find a common solution.
By default, the first paragraph is not indented in standard document classes due to the established typography traditions in different countries. Typically, indentation is required for all paragraphs. This is done by the option indentfirst=true
. Another option is to use a separate package indentfirst.
\setdefaultlanguage[indentfirst=true,forceheadingpunctuation=false]{russian}
The size of the red line is adjusted by modifying the value \parindent
:
\setlength{\parindent}{1cm}
The size of the indentation between lines can be adjusted through the package setspace. For example, an indent of 1.5 is set through \onehalfspacing
.
Pagination and padding around the page
Usually, you need an A4 format with specified padding from different edges of the page.
The requirements for the room are as follows:
-
Started with 2. The first page will be the title page. It is prepared separately.
-
It was always in the upper right corner.
Number 2 will start anyway, because there is also a standard title page, which can be omitted from the markup. Setting the position of the page number can be done using the package fancyhdr. Below is an example of how to achieve this:
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{\thepage}
\setlength{\headheight}{1.5em}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancypagestyle{plain}{%
\fancyhf{}%
\rhead{\thepage}}
Other header and footer formatting can also be customized through this package.
Page padding can be adjusted through the package geometry:
\RequirePackage[a4paper, headsep = 0.5 \headsep, left=2.5cm, right=2.1cm, top=2cm, bottom=2.1cm]{geometry}
There is a useful package layout, which allows you to visualize the different padding on the page and what commands are defined for them.
Headings
By default, the headers will be formatted as shown in the example. It is often necessary not to put a period at the end of the number and other formatting. The dot after the number can be disabled via the option forceheadingpunctuation
:
\setdefaultlanguage[indentfirst=true,forceheadingpunctuation=false]{russian}
Header formatting can be done through the package titlesec. For example, this is how you set up the format for \section{...}
:
\titleformat{\section}
{\filcenter\normalsize}
{\thesection}
{1ex}{#1}
Center alignment of size \normalsize
. A number is added \thesection
and an indent of 1ex. This is the size of the height of the character x
in the current font. The sizing options are quite diverse and it is recommended that you familiarize yourself with them. Such combinations can often be found in different tips on forums or packages.
For the purposes of completing the thesis, the \subparagraph
has been chosen for the design of the title pIn 2014, the Netherlands announced that it would It is rarely used in the body text, and it is more likely that other packages will also take this command into account. As a matter of fact \subparagraph
logically becomes at the team level \section
in the text. This will require some modifications in a few places to ensure that the visual formatting is displayed correctly. In text editors, such a command already has automatic support for displaying in the navigation bar. This makes it easier to find the right place in a large document.
Table of Contents and Hyperlinks
For ease of navigation, you often need to create a table of contents in a document. The table of contents can be customized using the package tocloft. For example, you can use this command to change the indentation before names \subparagraph
in the table of contents. This is how this command was chosen to identify applications, and it is necessary that the names are visually aligned with the names \section
in the table of contents.
\cftsetindents{subparagraph}{\cftsubsecindent}{0pt}
Viewing documents electronically allows you to quickly navigate to specific locations using hyperlinks. If you’ve ever looked at a PDF document and noticed that there are hyperlinks to different places in the document by formula number, source list, or figure, then most likely the document was made with LaTeX/XeLaTeX and a wonderful package hyperref
. With it, you can configure various aspects of the behavior of hyperlinks:
\RequirePackage{hyperref}%
\hypersetup{%
bookmarksnumbered, % номера section, subsection и т. д. попадали в название закладок в pdf документе. Если эту опцию отключить, то pdf закладки, для приложений, будут с пустым текстом.
unicode=true, % русские буквы в закладках PDF
linktoc=all, % ссылки на названиях и номерах страниц в toc
bookmarksdepth=3 % глубина закладок в pdf файле
}%
If we add the use of the package and the generation of the table of contents to the starting example:
hello_xelatex_toc.tex
\documentclass[12pt, oneside]{extarticle}
\usepackage{polyglossia}
\setdefaultlanguage[indentfirst=true,forceheadingpunctuation=false]{russian}
\setotherlanguages{english}
\IfFontExistsTF{Times New Roman}
{\setmainfont{Times New Roman}
\newfontfamily\cyrillicfont{Times New Roman}[Script=Cyrillic]}
{\setmainfont[Script=Cyrillic]{FreeSerif}}
\IfFontExistsTF{Courier New}
{\setmonofont{Courier New}
\newfontfamily\cyrillicfonttt{Courier New}[Script=Cyrillic]
}
{\setmonofont[Script=Cyrillic]{FreeMono}}
\IfFontExistsTF{Arial}
{\setsansfont{Arial}
\newfontfamily\cyrillicfontsf{Arial}[Script=Cyrillic]
}
{\setsansfont[Script=Cyrillic]{FreeSans}}
\usepackage{hyperref}
\title{Привет XeLaTeX}
\author{Автор}
\date{\today}
\begin{document}
\maketitle
\clearpage
\tableofcontents
\clearpage
\section{Введение}
\subsection{Сгенерированный текст языковой моделью (пунктуация и орфография оригинальная)}
Latex - это система компьютерной вёрстки, разработанная для создания технической и научной документации, а также других видов печатной продукции. Она широко используется в академических кругах, научно-исследовательских институтах и промышленных предприятиях для создания различных документов, включая научные статьи, учебники, технические отчёты и т.д. Latex предоставляет набор инструментов и команд для форматирования текста, составления математических формул, графиков, таблиц и других элементов документа. Одной из главных особенностей Latex является его расширяемость и возможность создания собственных команд и стилей.
{\sloppy
}
\end{document}
There is an important point here with the recompilation. If you compile with the xelatex
document once, the table of contents will not be generated, but instead there will be an almost blank page:
After restarting, a table of contents will be generated with the expected information:
That’s because it takes two compilation passes to form a table of contents. After the first pass, the service information for the table of contents is generated, which is used in the second pass. In the PDF document of the area, in the red frame, you can click and go to the desired place.
latexmk
Run the compilation several times and you will have a document with a ready-made table of contents. In this regard, it is easier to start using this command from the very beginning instead of xelatex
:
latexmk -synctex=1 -latexoption='-halt-on-error -enable-etex' -xelatex ./hello_xelatex_toc.tex
Drawing design
There are wonderful packages PGFPlots and PGF/Tikz. On the use of PGFPLots, we have already written about the main features (here is the process of plotting from tabular data). Only the main points will be covered below.
Usually, there is a question with inserting pictures and setting up captions for them. You can use the caption. This command allows you to change the format of captions, numbering logic for figures and tables:
% Настройка вида подписи: [ Рис. номер ]. Нумерация рисунков и таблиц в пределах section.
\captionsetup{labelsep=space, hypcap=false, figurewithin=section, tablewithin=section}
Drawings are usually arranged in a figure setting:
\begin{figure}[H]
\centering
...
\caption{Подпись}
\label{метка для ссылок}
\end{figure}
Here you should pay attention to the option [H]
From the Package float. By default, due to TeX algorithms, figures and tables may not be placed in the location where they are defined in the markup. This is to make their placement more readable. The picture may not fit in the rest of the page. Often, this behavior is not necessary, and it is necessary to place the picture or table exactly as defined in the markup, even if there is empty space. On the other hand, the use of dynamic positioning with hints would like to be possible as well. There are additional modifiers for this. \label
It is used when there is a need to refer to a figure somewhere in the text. A package can help you organize your links cleveref.
One of the requirements for the thesis was to indicate the total number of figures. You can do this by using the totcount
:
-
Create a new counter:
\newtotcounter{totfigures}
. -
Create a new environment
gostfigure
in which 1 is added to the counter each time\newenvironment{gostfigure}{\stepcounter{totfigures}}{}
.
This is not the only option and there may be other solutions. With the definition of the new environment, it was done on purpose to make the designation of what should be considered more explicit. You can make a simple command or try to supplement the logic of the standard environment figure
. In the place where you want to display the total number, it is enough to write \total{totfigures}
.
The possibilities of XeLaTeX are quite rich in terms of programming, so let’s look at some examples of how you can get drawings that can be changed dynamically. For example, dynamically generating points on half a grid of a given size:
fig1.tex
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}
\tikzmath { \total = 6; }
\draw [help lines] (0,0) grid (\total, \total);
\foreach \row in {1,2,...,\total}
\foreach \x in {1,...,\row} {
\filldraw (\x,\row) circle [radius=0.25];
}
\end{tikzpicture}
\end{document}
An example in Fig. below (can be enlarged):
\total
You can change it to a different value and you will get an updateIn 2014, the Netherlands announced that it The standalone document class is used here. It can be used for cases when there are many such drawings and you do not need to perform all the calculations again. A drawing is created once and saved as a PDF. Next, it is connected to the main document via \includegraphics
. Optionally, you can specify your own document class, on the basis of which the main document is created \documentclass[class=<свой_класс_документа>,tikz]{standalone}
. This helps to avoid visual differences in fonts or sizes.
Usually, when working on a thesis or some research in a field closer to experimental science, the work is iterative. First, there is the stage of studying the material, conducting experiments, obtaining the results and their design. The need to document the results can arise quite often. The ability to build graphs based on tabular data or change dynamically depending on the parameters allows you to simplify and automate this work. In case of any clarifications, it is enough to change the parameters or data and recompile the document.
Drawings in the form of images can be inserted through \includegraphics
. More on this.
Table formatting
Some of the table design concepts are the same as the figures. Instead of surroundings figure
Used table
. The positioning can be the same as for drawings. The calculation of the total number is also implemented. Tables can be created manually, as in the example below:
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|}
\hline
67 & 67 & 7 \\
\hline
\end{tabular}
\end{table}
Or create from a file. Let’s consider this option in more detail, because there are quite a lot of different examples about the first one. Let’s go back to the cycle of experiments. In addition to visualizing data in the form of graphs, sometimes it is necessary to arrange them in the form of a table. Manual migration is not the best option because the data can change frequently and there can be a lot of tables.
There is a package PGFplotsTable
that help in solving the problem. With it, you can load tables from files in the format of values separated by a character from a specific list. For example, the csv format is quite suitable.
For example, let’s look at the table:
Date |
Index |
Quantity |
Meaning |
---|---|---|---|
2022-03-15 |
a1 |
2 |
10.91238343 |
2022-04-22 |
a2 |
10 |
5.1219291293 |
2022-05-11 |
a2 |
1 |
15.10211201232 |
2022-06-20 |
a2 |
5 |
10.627932758025 |
2022-07-25 |
b2 |
10 |
8.0238721875392 |
2022-08-30 |
c1 |
2 |
7.199821676210851 |
2022-09-26 |
c1 |
1 |
9.129023840252350 |
2022-10-27 |
c1 |
3 |
12.62898129824398 |
2022-12-05 |
b2 |
1 |
13.37192878735851 |
2023-01-30 |
b3 |
4 |
6.92389073515 |
If the table can change at any time, it will be enough to replace the file and recompile the document.
With pgfplotstable, you can draw the entire table or a subset of it in different ways.
table.tex
\documentclass[14pt, oneside]{extarticle}
\usepackage{polyglossia}
\setdefaultlanguage[indentfirst=true,forceheadingpunctuation=false]{russian}
\setotherlanguages{english}
\IfFontExistsTF{Times New Roman}
{\setmainfont{Times New Roman}
\newfontfamily\cyrillicfont{Times New Roman}[Script=Cyrillic]}
{\setmainfont[Script=Cyrillic]{FreeSerif}}
\IfFontExistsTF{Courier New}
{\setmonofont{Courier New}
\newfontfamily\cyrillicfonttt{Courier New}[Script=Cyrillic]
}
{\setmonofont[Script=Cyrillic]{FreeMono}}
\IfFontExistsTF{Arial}
{\setsansfont{Arial}
\newfontfamily\cyrillicfontsf{Arial}[Script=Cyrillic]
}
{\setsansfont[Script=Cyrillic]{FreeSans}}
\usepackage{float}
\usepackage{pgfplots}
\usepackage{pgfcalendar}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\pgfplotstableset{use comma,
col sep=comma,
sort,
sort key=name,
sort cmp={string <},
columns/date/.style={column name={Дата}, date type={\day-\month-\year}},
columns/name/.style={string type, column name={Имя}},
columns/value/.style={fixed, zerofill, column name={Значение}, dec sep align},
header=true,
columns/quantity/.style={int detect, column name={Количество}}
}
\begin{document}
\section{Оформление таблиц}
\pgfplotstableread{%
date,name,quantity,value
2022-03-15,a1,2,10.91238343
2022-04-22,a2,10,5.1219291293
2022-05-11,a2,1,15.10211201232
2022-06-20,a2,5,10.627932758025
2022-07-25,b2,10,8.0238721875392
2022-08-30,c1,2,7.199821676210851
2022-09-26,c1,1,9.129023840252350
2022-10-27,c1,3,12.62898129824398
2022-12-05,b2,1,13.37192878735851
2023-01-30,b3,4,6.92389073515
}\data
\begin{table}[H]
\centering
\caption{Пример таблицы с двумя столбцами}
\pgfplotstabletypeset[columns={name,value}]\data
\end{table}
\begin{table}[H]
\centering
\caption{Вся таблица}
\pgfplotstabletypeset\data
\end{table}
\pgfplotstableset{
columns/value/.append style={dec sep align={c|}, column type/.add={|}{|}},
every head row/.style={before row=\hline, after row=\hline},
every even row/.style={after row=\hline},
every odd row/.style={after row=\hline},
every column/.style={column type/.add={|}{}},
every last column/.style={column type/.add={}{|}},
}
\begin{table}[H]
\centering
\caption{Вся таблица с границами}
\pgfplotstabletypeset\data
\end{table}
\end{document}
In \pgfplotstableset
Global settings are set for all tables. The types of all columns and the names that will be displayed in the document are explicitly spelled out. Settings can be prescribed individually for each table \pgfplotstabletypesetfile
. Usually, it is convenient to prescribe the general settings right away. Next, the table is loaded by name data
: \pgfplotstableread{...}\data
. For convenience, the contents of the table are inserted directly into the document markup. You can replace the table of contents with the path to the file. Several times, this table is displayed in different variants with different subsets of the data. By default, the tables will have no lines around the cells, as shown in Fig. below (image can be enlarged):
There are a few things to note:
-
The date is displayed differently than in the file. Changed order from YYYY-MM-DD to DD-MM-YYYY.
-
The rows are sorted by name.
-
Floating-point values are aligned with the symbol
,
and padded 0 to the same number of decimal places.
As a result, the table doesn’t look like it’s stored in the file if you just read it. Alignment of Numbers Relative to ,
Gives a visually more pleasing look to the table. There are many ways to change the view.
Lines around cells can be added by modifying global or local settings as follows:
\pgfplotstableset{
columns/value/.append style={dec sep align={c|}, column type/.add={|}{|}},
every head row/.style={before row=\hline, after row=\hline},
every even row/.style={after row=\hline},
every odd row/.style={after row=\hline},
every column/.style={column type/.add={|}{}},
every last column/.style={column type/.add={}{|}},
}
Here you should pay attention to the design columns/value/.append style={dec sep align={c|}, column type/.add={|}{|}}
. Due to the way the tables are eventually represented in XeLaTeX, the value column will be without vertical lines. They are separately added to the comanDoi column type/.add={|}{|}
and the alignment is now relative to dec sep align={c|}
. As a result, vertical lines with alignment relative to ,
will be saved.
The last example is to display a long table with several pages. You need to use a package longtable and Cleveref:
\pgfplotstabletypeset[font=\small
,begin table = \begin{longtable}
,end table = \end{longtable}
,every head row/.append style={before row={%
\caption{Таблица с разрывом}
\label{tab:long_table}\\
\hline
\endfirsthead
\caption*{Продолжение таблицы~\cref{tab:long_table}}\\
\hline
col 1 & col 2 & col 3\\
\hline
\endhead
}
}
,every first row/.append style={before row ={
col 1 & col 2 & col 3\\
\hline
}
}
, columns={id,num,text}
]{\loadedtable}
Under \loadedtable
It can be any previously uploaded table (an example is in the repository with the code for this article), or a file name with columns: id
, num
, text
. The only inconvenience is the need to manually change the column numbers that should be on each page col 1 & col 2 & col 3\\
, when their total number changes. This depends on the formatting requirements. At the time of creating this example, the thesis needed to number the columns in the long tables.
Formatting the List of Sources
Although there is a standard way for XeLaTeX to add and store a list of sources via BibTeX, Biber. The easiest way for the author to insert such a list was through the standard environment:
\begin{thebibliography}{11}
\bibitem{Bard} Бард Й. Нелинейное оценивание параметров / Й. Бард, Москва: Статистика, 1979. 349 c.
\end{thebibliography}
In BibTeX, it is difficult to struggle with the correct formatting of links, and there were certain problems with unicode, which caused some point to disappear, incorrect sorting, etc. Biber is more modern in this regard. Perhaps, at the moment, all the problems have been solved and these systems can be used. By default, the number will be in the format [1]
. It can be overridden with the following commands:
\makeatletter
\renewcommand\@biblabel[1]{#1.}
\makeatother
#1
This is the source number. In the requirements for the thesis, there was also a calculation of the total number of sources, then you can slightly modify the behavior of the command \bibitem
:
\pretocmd{\bibitem}{\stepcounter{totreferences}}{}{}
This adds additional logic before each command call \bibitem
, namely an increase in the total number of sources.
With thebibliography
The process is simple. Insert text in the correct order of characters and add an identifier \bibitem
, which is used in the text when quoting. To do this, it is convenient to use External systems.
The only inconvenience will be that you will have to sort the order of records correctly when adding or removing new sources, depending on the final requirements.
Programming in XeLaTeX
These are additional features of XeLaTeX that can be used for a variety of purposes. In the requirements for the thesis, it was necessary to indicate the total number of figures, tables, etc. in the abstract. There have already been examples of how to calculate this number, but the question remains how to print it in the text. The problem here is the declension of the words. For example, 1 drawing, 2 drawings, 5 drawings. The form of the word changes depending on the quantity.
You can solve this problem using the following commands from the package etoolbox. The algorithm was based on this article.
Defining Endings
\newcommand*{\figoneendian}{\total{totfigures}~рисунок}
\newcommand*{\figfourendian}{\total{totfigures}~рисунка}
\newcommand*{\figfiveendian}{\total{totfigures}~рисунков}
% Расчёт значений для общего числа рисунков
\newcommand*{\printtotfig}[1][,]{%
\boolfalse{less11Q}%
\boolfalse{greater19Q}%
\setcounter{Ptempnumexpr}{0}%
\addtocounter{Ptempnumexpr}{\numexpr\totvalue{totfigures}-100*(\totvalue{totfigures}/100)}%
\ifnumequal{\totvalue{totfigures}}{-1}%
{??#1}%
{\ifnumequal{\totvalue{totfigures}}{0}{}%
{\ifnumless{\value{Ptempnumexpr}}{11}{\booltrue{less11Q}}{}%
\ifnumgreater{\value{Ptempnumexpr}}{19}{\booltrue{greater19Q}}{}%
\ifboolexpr{bool {less11Q} or bool {greater19Q}}%
{\setcounter{Pwordindex}{0}%
\addtocounter{Pwordindex}{\numexpr\value{Ptempnumexpr}-10*(\value{Ptempnumexpr}/10)}%
\ifnumequal{\value{Pwordindex}}{1}% Окончание для 1
{\figoneendian#1\ }%
{\ifnumequal{\value{Pwordindex}}{2}% Окончание для 4
{\figfourendian#1\ }%
{\ifnumequal{\value{Pwordindex}}{3}%
{\figfourendian#1\ }%
{\ifnumequal{\value{Pwordindex}}{4}%
{\figfourendian#1\ }%
{\figfiveendian#1\ }% Окончание для 5
}%
}%
}%
}%
{\figfiveendian#1\ }% Окончане для 5
}%
}%
}
We won’t go into detail about the example itself, because this is a more advanced level, and as you use XeLaTex, some of the constructs will become more understandable. In short, the principle of operation is as follows:
-
Commands for typing the necessary words in different forms are defined:
\figoneendian, \figfourendian, \figfiveendian
. -
Checks to see if the values for the total count counter have been determined. If not, then the ??. is displayed
-
The digit with which the number ends is determined and the corresponding ending is chosen.
Team \printtotfig
It is used in cases where you need to display the relevant information.
Findings
In this article, we’ve looked at how to start using XeLaTeX. What tools will make it easier to get to know and work with? How to adjust the formatting of the main elements of text, as well as some useful packages for working with figures and tables. A few words about various aspects of automation.
If XeLaTeX is chosen as the main tool, then as problems arise and they are solved, you will have more knowledge about how else you can simplify the process of creating texts of varying complexity and how everything works internally.
For further study, you can look to the side koma-script. These are more modern analogues of popular document classes, in which many aspects of formatting are already taken into account in the options.
———-
Acknowledgment and Usage Notice
The editorial team at TechBurst Magazine acknowledges the invaluable contribution of the author of the original article that forms the foundation of our publication. We sincerely appreciate the author’s work. All images in this publication are sourced directly from the original article, where a reference to the author’s profile is provided as well. This publication respects the author’s rights and enhances the visibility of their original work. If there are any concerns or the author wishes to discuss this matter further, we welcome an open dialogue to address potential issues and find an amicable resolution. Feel free to contact us through the ‘Contact Us’ section; the link is available in the website footer.