=Paper=
{{Paper
|id=Vol-2803/paper23
|storemode=property
|title=A program for generating tex source files producing graphic
output (short paper)
|pdfUrl=https://ceur-ws.org/Vol-2803/paper23.pdf
|volume=Vol-2803
|authors=Victor N. Fomenko,Victor V. Garbaruk,Nina V. Popova
}}
==A program for generating tex source files producing graphic
output (short paper)==
A program for generating tex source files producing graphic
output
Victor N. Fomenkoa, Victor V. Garbarukb, Nina V. Popovac
a
LLC "New Technologies and Service" St. Bolshaya Raznochinnaya, house 14, lit. A, room 101,
Saint-Petersburg, 197110, Russia
b
Emperor Alexander I State Transport University, Moscow avenue 9, Saint-Petersburg, 190031, Russia
c
Peter the Great St. Petersburg Polytechnic University, Polytechnicheskaya st., 29,
St. Petersburg, 195251, Russia
Abstract
In this work a package of applications is described that is aimed to enhance graphic facilities
of the Latex typesetting system [1, 2]. The package is built up by the fusion of the Latex
formatting and graphic tools, on the one hand, and flexibility and computational aids of
FORTRAN 95 [2], on the other. As a result, the program allows to easily create pictures
containing many repeating elements or elements varying in a regular manner, automatically
hatching a selected domain, inserting formatted objects (a formula, for instance) at any point
of the image. The package enables us to create 3D object images as seen along a certain
direction. An automatic drawing of their plane sections may be also done.
Keywords 1
computer graphics, Latex, 3D graphics, Fortran.
1. Introduction Another approach is to convert images and
graphs from powerful mathematical software
Creating pictures, using WORD also, is not packages Matlab [7], Mathematica [8],
a simple task. LaTeX [1, 2, 3] is a popular TeX GeoGebra [9] and many others into "LaTeX-
typesetting package that makes it easy to type code".
complex documents. The package allows you to There are a number of packages working
automate many tasks of typing books, well with LaTeX. We list some of these
educational materials, scientific articles. In packages, but a detailed discussion of their
distance learning LaTeX is actively used to merits and demerits is beyond the scope of this
create multivariate assignments in various article. MetaPost [10] is a graphical drawing
disciplines [4, 5]. Most documents created by editor for LaTeX. The package is based on the
means of LaTeX also contain graphics and METAFONT [11] program created by Donald
illustrations for better understanding of the text. Knuth for the development of vector fonts for
Adding visual elements to text can be done in TeX. The Asymptote package [12] overcomes
different ways. some of the MetaPost limitations. The
There are many different charting and data LaTeXDraw package [13] can be used to
visualization systems that can be saved in PDF generate PSTricks code or directly create PDF
format. These objects are then included in the pictures. PGF / TikZ is a tandem of languages
text of the document prepared by LaTeX [6]. for producing vector graphics from geometric
and algebraic descriptions. PGF is a lower-level
language, while TikZ is a set of higher-level
Models and Methods for Researching Information Systems in
Transport, December 11–12, 2020, Saint Petersburg, Russia
EMAIL: vfomenko1943@gmail.com (Fomenko);
vvgarbaruk@mail.ru (Garbaruk); ninavaspo@mail.ru (Popova)
ORCID: 0000-0001-6185-9343 (Fomenko); 0000-0002-9983-
4712 (Garbaruk); 0000-0003-3058-7386 (Popova)
©️ 2020 Copyright for this paper by its authors. Use permitted under
Creative Commons License Attribution 4.0 International (CC BY 4.0).
CEUR Workshop Proceedings (CEUR-WS.org)
166
macros that use PGF [13-20]. The close parameters can be set by the user. Line
relationship between TikZ and PGFPlots width can also be user-defined.
allows, firstly, to effectively integrate charts
into various drawings made in TikZ, as well as 3. Creation of drawings
to use the TikZ capabilities when working with
charts [20].
In this package, the user has to write a
In this work software is described which is
Fortran 95 program. The input file created for
aimed to make it easier (or, in many situations,
the LaTeX system is processed by the LaTeX
even possible at all) to produce complicated
translator into the PDF file shown in the figures
images for those who use Latex system.
below. We note the following features of the
Because of this reason the graphic tool under
figures constructed using the described
consideration can prove to be very useful. In
software package:
this package, the user should write a program in
automatic hatching over a domain with
the Fortran 95 language [21]. If the figure is
the boundary defined parametrically (fig.
inserted into the text, then the Fortran 95
1);
program ends with subroutine final, and
subroutine prep (fn, dims, hrange, vrange, nh, images of flat pictures with
nv, margin) listing the insert parameters begins. repeating elements, for example,
Otherwise, the result is obtained in the PDF electrical circuits (fig. 2, 3).
form.
An important feature of the present way to
explore the Latex graphics is performed using
facilities of the flexible and well-developed
language FORTRAN 95, rather than within the
Latex system itself. This language has a library
of numerous built-in functions, in particular
those which deal with strings, what is important
for making files of the tex type. In contrast to
this, the graphic applications developed
recently are often based on programming
within the Latex system which is less capable
of implementing algorithms, especially
computational ones.
2. Brief description of graphics
Figure 1: Hatching
utilities
We will give a brief description of the
utilities (their total number is more than 80)
that can be used to create drawings. First of
all, the size of the picture is set, then the
ranges for the auxiliary coordinates along
the horizontal and vertical axes are
indicated, the coordinate axes are
displayed, they can be provided by
numbered divisions and additional marks.
Note that the coordinates of the points in the
displayed image are set in arbitrary units.
The horizontal and vertical scale is Figure 2: Grafik
determined basing on the size of the picture
and the range of coordinates in arbitrary
units along the horizontal and vertical lines.
In most cases, the lines forming the picture
can be solid or dashed, and the dash-size
167
Figure 3 shows a regular 15-faced
polyhedron. Below are fragments of the code
i that provides its 2D image.
1) Specifying the coordinates of vertices of the
polytope.
n=7
do k=1,n
V(:,k)=(/cos(2*pi/n*k),sin(2*pi/n*k),0./)
V(:,k+n)=(/cos(2*pi/n*k),sin(2*pi/n*k),1./)
enddo
V(:,2*n+l)=(/0.,0.,2.3/)
Figure 3: Electrical circuit 2) Specifying faces by indicating three vertices.
do k=1,n
f_index(:,k)=(/k,mod(k,n)+1,k+n/)
4. Imaging of 3D objects enddo
do k=1,n
The algorithm implemented in this work f_index(:,n+k)=(/2*n+1 ,n+k,n+mod(k,n)+1/)
corresponds to the photographic process of a enddo
removed object if the size of the latter is much f_index(:,2*n+1)=(/1,2,3/)
less than the distance between it and the 3) Setting the cutting plane.
camera. Т=(–0.5,1.,0.5)
In particular, it is possible to display spatial 4) Setting a vector that determines
curves and convex polyhedrons. The direction the direction of observation.
in which the object is viewed is set by vector SCREEN=(/-1.,0.6,-0.8/)
(, , ) defining the position of the screen. To 5) Image of vertex names.
obtain, for example, an isometric projection, do k=1,n
you may take = 1/3, = 1/3, = 1/3. write(ind,'(i2)')k
The position of the camera with respect to if (k/=3.and.k/=5) then
its axis is chosen so that vertical elements are uhr=5
depicted vertically as well. else if (k==3) then
To picture convex polytopes one should uhr=2
indicate the Descartes, cylindrical or spherical else
coordinates of the vertices. Besides one should uhr=9
specify for each face the vertices which lie in it. endif
The program determines which vertices are call put(V(:,k),'$A_{'//trim(adjustl(ind))//'}
connected with edges. Also the edges are found $',
out which are non-visible for the given viewing d=5.,
direction. Such edges are imaged by dash lines. uhr=uhr)
An automatic denotation of vertices is available call
too. Given the equation of a plane, the program put(V(:,k+n),'$B_{'//trim(adjustl(ind))//'}
builds the cut of the polytope by this plane. $',d=5.,
Note some features of the images produced uhr=uhr)
by described software: enddo
authenticity, i.e., exact reproduction of
geometrical properties up to the size of
pixels depicting the image;
imaging of 3D objects and their plane
sections in strict accordance with the rules
of orthographic projection.
image and shading of flat sections of a
spatial figure;
rendering of features after rotation
about any spatial axis.
168
You can also get an image of a spatial object
after rotation around any spatial axis, specified
by the direction cosines cx, cy, cz, by an
arbitrary angle . After the rotation, the point
with coordinates x, y, z moves to the point with
the coordinates x, y, z [22],which is
calculated by the formula
x α1 β1 γ1
,
y α 2 x β 2 y γ 2 z
z α β γ
3 3 3
Figure 4: Polytope
α1 λ 0 λ1 λ 2 λ 3
2 2 2 2
where ;
α 2 2(λ 0 λ 3 λ1λ 2 )
The constructed spatial figure can be viewed
from various sides by changing the vector that α 2(λ λ λ λ )
determines the direction of observation. Fig. 5, 3 0 2 1 3
6 show top and side views of the previously
built Polytope. The parameters of the β1 2(λ 0 λ 3 λ1λ 2 )
observation vectors SCREEN = (/0.,0.,-1./) and 2 2;
β 2 λ 0 λ1 λ 2 λ 3
2 2
SCREEN = (/-1.,0.,0./) correspond to these
β 2(λ λ λ λ )
figures. 3 0 1 2 3
γ1 2(λ 0 λ 2 λ1λ 3 )
.
γ 2 2(λ 0 λ1 λ 2 λ 3 )
γ λ 2 λ 2 λ 2 λ 2
3 0 1 2 3
Rodrigo-Hamilton parameters
0 , 1, 2 , 3 are calculated by the formulas:.
λ cos(θ / 2), λ c sin(θ / 2), .
0 1 x
λ 2 c y sin(θ / 2), λ3 cx sin(θ / 2) .
This subroutine is useful for analyzing
spatial curves. Figure 7 shows different types of
a conical helix defined by the following
Figure 5: View from above parametric equations:
x(t ) t cos t ;
y (t ) t sin t ;
z (t ) t.
Figure 6: Side view Figure 7: Curves in space
169
y = t**2 – 2*t + 2 + C*exp(–t)
end function у
5. Plotting functions 2) Description of isocline (2).
real function qy(t)
real t
The main disadvantage of the PICTURE
qy=t**2-C1
graphic package and its EPIC and EEPIC
end function qy
extensions used in the LaTeX system is their
3) display of ten isoclines,
orientation towards manual work. For example,
N=10
they allow you to display a graph, but it is
do i=1,N
assumed that the coordinates of the points will
C1=(Cmax-Cmin)/N*i+Cmin
be entered by the programmer as command
call curve(-2.,2.,q,qy,1000)
arguments. In this package, the user only has to
4) display of arrows specifying the direction on
write a Fortran 95 program that defines the
isoclines,
curve parametrically. To construct a curve, call
do k=0,kmax
the corresponding subroutine of the package,
call vector($L1((/q(-2.+4./kmax*k),
and the names of the procedure defining the
qy(-2.+4./kmax*k)/),&atan(C1),4.))
curve are included as parameters of this
enddo
subroutine. It is possible, if necessary, to
5) Display of a partial solution.
display a large number of illustrating elements
C = –1.
(arrows, lines, etc.).
call curve(–2.,2.,q,qy,1000,width=5)
Figure 9 was created to graphically
illustrate the solution of the differential
2
y
equation y .
x
Figure 8: Solution of the equation у' + y = t 2
y
Figure 9: Solution of the equation y
Figure 8 was created to graphically x
illustrate the solution of the differential
equation у' + y = x2. It shows how the integral 6. Conclusion
curve intersects the isoclines at the
direction along the arrows going out from An important difference of this approach
the given isocline. Below are several from using Latex graphics is its hybrid nature.
subroutines that provide the construction Programming is carried out not within the
of Figure 4. framework of the Latex system, but by means
1) Solution of the differential equation, of the flexible and well-developed language
real function y(t)
170
FORTRAN 95. This language has a rich library AT&T Bell Laboratories, Murray Hill,
of built-in functions, in particular, functions for New Jersey, 1992.
working with strings, which is especially [11] Knuth D. The METAFONTbook. Addison
important for creating tex source files. On the Wesley, Boston, 1986.
contrary, currently developed graphical [12] Asymptote: The Vector Graphics
applications usually focus on programming in Language.
the Latex system itself, which has fewer URL: http://asymptote.sourceforge.net.
facilities for implementing algorithms, [13] http://latexdraw.sourceforge.net
especially computational ones. [14] Kuretenko U. A. TikZ & PGF. Grafiics of
A significant advantage of this approach is Document LaTeX. Rostov-Don, 2014.
its ability to extend itself by creating new URL:http://elib.ict.nsc.ru/jspui/
procedures based on those already written in handle/ICT/1488.
Fortran. [15] Tantau T. TikZ and pgf manual. Version
1.01. URL:
References http://sourceforge.net/projects/pgf/.
[16] Mertz A., Slough W. Graphics with PGF
and TikZ. TUGboat, Volume 28, No. 1
[1] Goossens, M., Mittelbach, F., Rahtz S.,
(2007) 91-99, Proceedings of the Practical
Voss, H. The LaTeX Graphics
TEX 2006 Conference. URL: http://
Companion, Second Edition, New York,
works.bepress.com/william_slough/5/.
Addison-Wesley, 2008.
[17] Feuersanger C. Manual for Package
[2] Spivak M. The Joy of TEX. A gourmet
pgfplots - 2D/3D Plots in LATEX. Vers. 1.
guide to typesetting with the AMS-
URL:
TEXmacro package. American
http://sourceforge.net/projects/pgfplotsDr.
Mathematical Society, Provi-dence, RI,
[18] Esajan А. R., Chubarikov V. N.,
1990.
Djbrovolski N. М., Jakushin А. V.
[3] Rozhenko A. I. Art of text composition in
Plotting using LaTeX-package pgfplots,
LATEX, Printing house of the State
izd-vo TGPU, Tula, 2015.
University, Novosibirsk, 2005.
[19] Plotting with TikZ and LaTeX.
[4] V.M. Karnaukhov LATEX application.
URL: http://pgfplots.net.
Generator of test options. Saarbrücken,
[20] Getreuer P. TikZ for High-Quality LaTeX
Germany, Lap lambert Academic
Pictures. URL:
Publishing, 2012.
http://www.sciweavers.org/tutorials/tikz-
[5] Lubyagina E.N., Yurlova E.S. Preparation
high-quality-latex-pictures.
of educational assignments in LATEX.
[21] Chapman, S.J. Fortran 90-95 for Scientists
(2014) Mathematical bulletin of
and Engineers, WCB/McGraw-Hill
pedagogical universities and universities
Higher Education, New York, 1998.
of the Volga-Vyatka region. No. 16. 289-
[22] Lurie A.I. Analytical Mechanics, Springer,
295.
Berlin, 2002.
[6] Baldin E. M. LaTeX computer printing
house, BHV- Petersburg, St.Petersburg,
2012.
[7] Gilat A., Subramaniam V. Numerical
methods for engineers and scientists: an
introduction with applications using
MATLAB. 3rd edition. John Wiley &
Sons, Inc. New York, 2014.
[8] Taranchuk V. B. Introduction to graphics
of the Mathematica system, BSU, Minsk:
2017.
[9] Kovács, Z., Parisse B. Giac and GeoGebra:
improved Grоbner basis computations,
RICAM Institute, Linz, 2013.
[10] Hobby J.D. A user’s manual for
METAPOST. Technical Report 162,
171