Научная статья на тему 'A program for generating tex source files producing graphic output'

A program for generating tex source files producing graphic output Текст научной статьи по специальности «Компьютерные и информационные науки»

CC BY
179
31
i Надоели баннеры? Вы всегда можете отключить рекламу.
Ключевые слова
computer graphics / Latex / 3D graphics / Fortran

Аннотация научной статьи по компьютерным и информационным наукам, автор научной работы — Victor N. Fomenko, Victor V. Garbaruk, Nina V. Popova

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.

i Надоели баннеры? Вы всегда можете отключить рекламу.
iНе можете найти то, что вам нужно? Попробуйте сервис подбора литературы.
i Надоели баннеры? Вы всегда можете отключить рекламу.

Текст научной работы на тему «A program for generating tex source files producing graphic output»

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 cPeter 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

Creating pictures, using WORD also, is not a simple task. LaTeX [1, 2, 3] is a popular TeX typesetting package that makes it easy to type complex documents. The package allows you to automate many tasks of typing books, educational materials, scientific articles. In distance learning LaTeX is actively used to create multivariate assignments in various disciplines [4, 5]. Most documents created by means of LaTeX also contain graphics and illustrations for better understanding of the text. Adding visual elements to text can be done in different ways.

There are many different charting and data visualization systems that can be saved in PDF format. These objects are then included in the text of the document prepared by LaTeX [6].

Another approach is to convert images and graphs from powerful mathematical software packages Matlab [7], Mathematica [8], GeoGebra [9] and many others into "LaTeXcode".

There are a number of packages working well with LaTeX. We list some of these packages, but a detailed discussion of their merits and demerits is beyond the scope of this article. MetaPost [10] is a graphical drawing editor for LaTeX. The package is based on the METAFONT [11] program created by Donald Knuth for the development of vector fonts for TeX. The Asymptote package [12] overcomes some of the MetaPost limitations. The LaTeXDraw package [13] can be used to generate PSTricks code or directly create PDF pictures. PGF / TikZ is a tandem of languages 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-99834712 (Garbaruk); 0000-0003-3058-7386 (Popova)

I Zee) CI) \ © ^ 2020 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0).

r» =1 CEUR Workshop Proceedings (CEUR-WS.org)

macros that use PGF [13-20]. The close relationship between TikZ and PGFPlots allows, firstly, to effectively integrate charts into various drawings made in TikZ, as well as to use the TikZ capabilities when working with charts [20].

In this work software is described which is aimed to make it easier (or, in many situations, even possible at all) to produce complicated images for those who use Latex system. Because of this reason the graphic tool under consideration can prove to be very useful. In this package, the user should write a program in the Fortran 95 language [21]. If the figure is inserted into the text, then the Fortran 95 program ends with subroutine final, and subroutine prep (fn, dims, hrange, vrange, nh, nv, margin) listing the insert parameters begins. Otherwise, the result is obtained in the PDF 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 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 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

parameters can be set by the user. Line width can also be user-defined.

3. Creation of drawings

In this package, the user has to write a Fortran 95 program. The input file created for the LaTeX system is processed by the LaTeX translator into the PDF file shown in the figures below. We note the following features of the figures constructed using the described software package:

• automatic hatching over a domain with the boundary defined parametrically (fig. 1);

• images of flat pictures with repeating elements, for example, electrical circuits (fig. 2, 3).

Figure 1: Hatching

Figure 2: Grafik

¿^rrHkHl

□ d d

0_^YYv| |-bYYv| |-UYYV| |J-O

Figure 3: Electrical circuit

4. Imaging of 3D objects

The algorithm implemented in this work corresponds to the photographic process of a removed object if the size of the latter is much less than the distance between it and the camera.

In particular, it is possible to display spatial curves and convex polyhedrons. The direction in which the object is viewed is set by vector (a, p, y) defining the position of the screen. To obtain, for example, an isometric projection, you may take a = 1/3, p = 1/3, y = 1/3.

The position of the camera with respect to its axis is chosen so that vertical elements are depicted vertically as well.

To picture convex polytopes one should indicate the Descartes, cylindrical or spherical coordinates of the vertices. Besides one should specify for each face the vertices which lie in it. The program determines which vertices are connected with edges. Also the edges are found out which are non-visible for the given viewing direction. Such edges are imaged by dash lines. An automatic denotation of vertices is available too. Given the equation of a plane, the program builds the cut of the polytope by this plane.

Note some features of the images produced by described software:

• 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.

Figure 3 shows a regular 15-faced polyhedron. Below are fragments of the code 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/)

2) Specifying faces by indicating three vertices. do k=1,n

f_index(: ,k)=(/k,mod(k,n)+1,k+n/)

enddo

do k=1,n

f_index(: ,n+k)=(/2*n+1 ,n+k,n+mod(k,n)+1/) enddo

f_index(:,2*n+1)=(/1,2,3/)

3) Setting the cutting plane. T=(-0.5,1.,0.5)

4) Setting a vector that determines the direction of observation.

SCREEN=(/-1.,0.6,-0.8/)

5) Image of vertex names. do k=1,n write(ind,'(i2)')k

if (k/=3.and.k/=5) then uhr=5

else if (k==3) then

uhr=2

else

uhr=9

endif

call put(V(: ,k),'$A_ {'//trim(adj ustl(ind))//'} $',

d=5.,

uhr=uhr)

call

put(V(:,k+n),'$B_{'//trim(adjustl(ind))//'}

$',d=5.,

uhr=uhr)

enddo

Figure 4: Polytope

The constructed spatial figure can be viewed from various sides by changing the vector that determines the direction of observation. Fig. 5, 6 show top and side views of the previously built Polytope. The parameters of the observation vectors SCREEN = (/0.,0.,-1./) and SCREEN = (/-1.,0.,0./) correspond to these figures.

Figure 5: View from above

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 0. 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

fx \ ( a ^ ( p^

y

v z

x +

V a3 J

ß2

V ß3 J

^Yi^

y+

where

f a1 >

a 2 =

V a3 J

A 2

Y 2 V Y3 J

2

2

A g + Ai — A 2 — A3

2(—A0A3 + AiA 2)

V 2(A 0A 2 + AiA3) J

f ßi ^ 2(A 0A3 + AiA 2) A

ß2 = A g2 — Ai2 + A 22 — A3 2

V ß3 J V 2(—A0Ai + A 2A3) J

f Yi ^ 2(—AgA 2 + AiA3) A

Y 2 = 2(A 0Ai + A 2 A3)

iНе можете найти то, что вам нужно? Попробуйте сервис подбора литературы.

V Y3 j VA02 — Ai2 — A22 + A3 2 J

parameters

Rodrigo-Hamilton , ^, X2, A3 are calculated by the formulas:.

A0 = cos(9 / 2), Aj = cx sin(9 / 2),.

A2 = cy sin(9 /2), Xi = cx sin(9 / 2).

This subroutine is useful for analyzing spatial curves. Figure 7 shows different types of a conical helix defined by the following parametric equations:

x(t ) = t • cos t; y(t ) = t • sin t; z (t ) = t.

Figure 6: Side view

Figure 7: Curves in space

a

z

2

5. Plotting functions

The main disadvantage of the PICTURE graphic package and its EPIC and EEPIC extensions used in the LaTeX system is their orientation towards manual work. For example, they allow you to display a graph, but it is assumed that the coordinates of the points will be entered by the programmer as command arguments. In this package, the user only has to write a Fortran 95 program that defines the curve parametrically. To construct a curve, call the corresponding subroutine of the package, and the names of the procedure defining the curve are included as parameters of this subroutine. It is possible, if necessary, to display a large number of illustrating elements (arrows, lines, etc.).

Figure 8: Solution of the equation y' + y = t

Figure 8 was created to graphically illustrate the solution of the differential equation y'+y = x2. It shows how the integral curve intersects the isoclines at the direction along the arrows going out from the given isocline. Below are several subroutines that provide the construction of Figure 4.

1) Solution of the differential equation, real function y(t)

y = t**2 - 2*t + 2 + C*exp(-t) end function y

2) Description of isocline (2). real function qy(t)

real t

qy=t**2-C1 end function qy

3) display of ten isoclines, N=10

do i=1,N

C 1=(Cmax-Cmin)/N * i+Cmin call curve(-2.,2.,q,qy,1000)

4) display of arrows specifying the direction on isoclines,

do k=0,kmax

call vector($L1((/q(-2.+4./kmax*k), qy(-2.+4./kmax*k)/),&atan(C1),4.)) enddo

5) Display of a partial solution. C = -1.

call curve(-2.,2.,q,qy,1000,width=5)

Figure 9 was created to graphically illustrate the solution of the differential

• , f ^2 equation y =1 —

Figure 9: Solution of the equation y' = I —

6. Conclusion

An important difference of this approach from using Latex graphics is its hybrid nature. Programming is carried out not within the framework of the Latex system, but by means of the flexible and well-developed language

2

FORTRAN 95. This language has a rich library of built-in functions, in particular, functions for working with strings, which is especially important for creating tex source files. On the contrary, currently developed graphical applications usually focus on programming in the Latex system itself, which has fewer facilities for implementing algorithms, especially computational ones.

A significant advantage of this approach is its ability to extend itself by creating new procedures based on those already written in Fortran.

References

[1] Goossens, M., Mittelbach, F., Rahtz S., Voss, H. The LaTeX Graphics Companion, Second Edition, New York, Addison-Wesley, 2008.

[2] Spivak M. The Joy of TEX. A gourmet guide to typesetting with the AMS-TEXmacro package. American Mathematical Society, Provi-dence, RI, 1990.

[3] Rozhenko A. I. Art of text composition in LATEX, Printing house of the State University, Novosibirsk, 2005.

[4] V.M. Karnaukhov LATEX application. Generator of test options. Saarbrücken, Germany, Lap lambert Academic Publishing, 2012.

[5] Lubyagina E.N., Yurlova E.S. Preparation of educational assignments in LATEX. (2014) Mathematical bulletin of pedagogical universities and universities of the Volga-Vyatka region. No. 16. 289295.

[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] Kovacs, Z., Parisse B. Giac and GeoGebra: improved Grobner basis computations, RICAM Institute, Linz, 2013.

[10] Hobby J.D. A user's manual for METAPOST. Technical Report 162,

AT&T Bell Laboratories, Murray Hill, New Jersey, 1992.

[11] Knuth D. The METAFONTbook. Addison Wesley, Boston, 1986.

[12] Asymptote: The Vector Graphics Language.

URL: http://asymptote. sourceforge. net.

[13] http://latexdraw.sourceforge.net

[14] Kuretenko U. A. TikZ & PGF. Grafiics of Document LaTeX. Rostov-Don, 2014. URL: http://elib.ict.nsc. ru/j spui/ handle/ICT/1488.

[15] Tantau T. TikZ and pgf manual. Version 1.01. URL:

http://sourceforge.net/proj ects/pgf/.

[16] Mertz A., Slough W. Graphics with PGF and TikZ. TUGboat, Volume 28, No. 1 (2007) 91-99, Proceedings of the Practical TEX 2006 Conference. URL: http:// works.bepress.com/william_slough/5/.

[17] Feuersanger C. Manual for Package pgfplots - 2D/3D Plots in LATEX. Vers. 1. URL:

http://sourceforge. net/proj ects/pgfplotsDr.

[18] Esajan A. R., Chubarikov V. N., Djbrovolski N. M., Jakushin A. V. Plotting using LaTeX-package pgfplots, izd-vo TGPU, Tula, 2015.

[19] Plotting with TikZ and LaTeX. URL: http://pgfplots.net.

[20] Getreuer P. TikZ for High-Quality LaTeX Pictures. URL:

http://www.sciweavers.org/tutorials/tikz-high-quality-latex-pictures.

[21] Chapman, S.J. Fortran 90-95 for Scientists and Engineers, WCB/McGraw-Hill Higher Education, New York, 1998.

[22] Lurie A.I. Analytical Mechanics, Springer, Berlin, 2002.

i Надоели баннеры? Вы всегда можете отключить рекламу.