Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

# Howto:Build graduate dials with LaTeX

In the construction of the G91-R1B I met the need to make several graduated dials, some of which are quite complex and long to be realized with Inkscape. Not only that, but manual realization often involves problems when changing the format, for example, if you do change the font size, you need to remake everything. Inkscape has a scripting language that automates the process, but I find it quite uncomfortable.
Manual realization with Inkscape of a graduated dials requires a not easy re-adaptation work. This fact makes difficult to reuse a previous job to adapt it to a new one.

As you will see in this article, I will try to make it possible for those who have never used LaTeX[1] to take advantage of it to achieve great graduated circles as well as graphic objects to be placed inside a canvas.

However, I recall that the PDF or PNG file produced by LaTeX is just a first step in the job, it will definitely be necessary to work with GIMP at least to adapt the image produced to the correct size required by FGFS. But this process is also necessary if you work with Inkscape, as many of you well know.

I want to make a Kollsman 1979U4 compass, the graduate dials is placed on a cone trunk, very low with a fairly moderate sloping wall. In this case, even if you are having perspective errors, you can 'bundle' the cone trunk with an image that will be 1024x64 pixels.
This is a fairly generic case, so the technique adopted can be extended to all similar tools. The important thing is to organize well the LaTeX program so that it is clear what we can change without changing the result. [2]

For the first example, we start from a graduated linear dial, it is a simple, fairly simple example to be realized with vector graphics programs, but when automated, as in this example, it makes it easy to reconfigure any type of gauge that has a size dominant over the others.
This example is made for the graduate dial of a Kollsman 1979U4 model compass installed on the top of the FIAT G91R1B aircraft panel.

% \documentclass{standalone} is particular class that non have a size, but the size is define from
% the document itself
\documentclass[tikz,margin=0pt]{standalone}
% \usepackage{tikz} is the package that contain the graphics command as \draw etc ...
% The package is describe in this document: https://www.sharelatex.com/learn/TikZ_package
\usepackage{tikz}
% If the graduate dials is for analogical gauges period 50-70 years, this font is ok
% OCR is open-source package deposited in the CTAN repository: https://www.ctan.org/pkg/ocr-b
% Opentype can be used on Linux and Mac machines
% (I do not know if it's possible in Windows, but I think of it),
% https://www.ctan.org/tex-archive/fonts/ocr-b-outline
\usepackage{ocr}
% Defines the font size to use, the first number defines the font size,
% the second number the dimensional family from which the font is taken.
% It can be assumed that there are differences between a dimensional family 10 and a 12 dimensional font.
\tikzset{font={\fontsize{18pt}{10}\selectfont}}
\begin{document}
% The link OCR package documentation is this: http://ctan.mirror.garr.it/mirrors/CTAN/macros/latex/contrib/ocr-latex/ocr.pdf
% \ocrfamily - Normal font family
% \ocrnegfamily - Family negative fonts
{\ocrfamily
% Xscale defines the scale of the drawing with respect to the document we write.
% It is imperative to make it compatible for the size of the graduated dial that we are designing.
% Its determination requires a number of tests to optimize the font dimension with the units of measurement.
\begin{tikzpicture}[xscale=0.05]
%5° Rays
\foreach \a in {0, 5,...,355}
\draw[line width=0.5mm] (\a,0) -- (\a,1.5mm);
%10° Rays
\foreach \a in {0, 10,...,350}
\draw[line width=0.5mm] (\a,0) -- (\a,2.0mm);
%30° Rays
\foreach \a in {0, 30,...,345}
\draw[line width=1mm] (\a,0) -- (\a,2.0mm);
%labels
\draw (30,0.7) node {33};
\draw (60,0.7) node {30};
\draw (120,0.7) node {24};
\draw (150,0.7) node {21};
\draw (210,0.7) node {15};
\draw (240,0.7) node {12};
\draw (300,0.7) node {6};
\draw (330,0.7) node {3};
\draw (0,0.7) node {N};
\draw (90,0.7) node {E};
\draw (180,0.7) node {S};
\draw (270,0.7) node {W};
\end{tikzpicture}
}
\end{document}


I think the code is pretty well commented, but there are a few comments:

\documentclass[tikz,margin=0pt]{standalone}


As with all advanced text editing systems, you must enter the document template: \documentclass. In LaTeX exists the standalone model that defines a non-size document class. This particular class is very useful when we want to rasterize the document directly in PNG. You also need to enter margins [tikz, margin = 0pt] to zero so that there is absolutely no border.

\usepackage{tikz}


The power of LaTeX is in the ability to customize your work using an "exaggerated" amount of modules (packages). What we use in this example is the {tikz}[3] graphic package, a program to integrate LaTeX graphics, graphs, diagrams and more, with a very clear syntax.

\usepackage{ocr}


The G91 is a plane that belongs to a precise historical era (project in the late 50's), so the instruments used reflect that era and the fonts used reflect the techniques needed to break the numbers on the metal support typical of the analog instruments. In this case, I noticed that the OCR-B font (born in 1969) reproduces very well 95% of the characters, only the number one was in reality 'I', but in this case I did not like to customize the character, what it did for the type of license it has, but which made my example more complicated to propose. However in CTAN[4] it is possible to propose characters closest to the aeronautical world and therefore make them available to all users. However, modifying the font and re-compiling the LaTeX code is trivial and this is one of the advantages of this technique.

\tikzset{font={\fontsize{18pt}{10}\selectfont}}


Font size is an essential element and in LaTeX it is handled very much. The main concept to know is that the font used in LaTeX can vary a lot depending on its basic size. For example, a font 6 may differ from font 10 as the readability of a font changes. This fact makes a font package, such as the ORC-B, actually made up of various subpackages made according to size, but also bold, italic, etc .. In this example, the first value {18} indicates the font size (in dot pt) that we want to display, while {10} is the size of the original font.

\begin{document} ... \end{document}


After so many things, the writing of the document begins, so what's inside the logical parentheses begin ... end will be compiled and possibly displayed.

{\ocrfamily ... }


It is another logical parenthesis that indicates that from now on you use the OCR family font, you can insert a different font family into a document. This function is certainly useful for very complex gauges that have embossed symbols or fonts with special features.

\begin{tikzpicture}[xscale=0.05]


Finally we say to the TikZ program that will start drawing a picture composed of graphic signs and characters, and that this image is on scale 0.05. If you change the value 0.05, for example with 1.0 you will see very small, but spaced signs. The X scale is that of the X axis, then obviously there is also the Y scale. This method seems complicated, but it is absolutely powerful because it allows to modify, with only one parameter, the dimensional characteristics of the figure we're going to draw. Obviously it can be used several times, changing the drawing scale even in subpages. In our case, being the dominant X scale, it is sufficient to only define the 0.05 value I found by doing some tests. This is also a parameter that can be defined once for all the gauges we want to build, it is useful because it allows to easily define the thickness of the lines in mm.

\foreach \a in {0, 5,...,355}


This is a loop, which allows you to define the variable \a various values according to a sequence we like. It is a very powerful feature that other programming languages (such as Python, Go etc ..) have inherited from LaTeX. Since variable \ a defines the position on the X axis of the dash at 5 degrees it is useful that the set in the loop is the one we want. You can further elaborate the variable \ a if we want to obtain sequences, as we will see in a later example. From a practical point of view, changing the number sequence involves changing the position of the smaller vertical lines.

\draw[line width=0.5mm] (\a,0) -- (\a,1.5mm);


Finally, now the program draws! The syntax is simple but powerful, says to draw a line ("-") of 0.5 mm thick (This is the size I actually measured for the compass) starting from \a X-coordinate (0..355 in steps of 5) and ending higher (Y axis) to 1.5 mm. Here, the power of the method becomes apparent that with a simple line of code, very readable, it can generate hundreds of rows in a completely parametric way.

\draw (30,0.7) node {33};


This command defines a "node" and its content is defined within the braces. The node, in the TikZ language, is a box where you can insert something, such as the number 33, but you can do something else like lowering font {\small 33} and much more according to LaTeX syntax. Or you can rotate the string at an angle by placing this attribute: \draw (30,0.7) node [rotate = 90] {33}; and so much more.

Finish work example of est Graduate dials for PHI

This is an example much more complex as the original instrument has a double graduated dial. Therefore, the program's implementation time in LaTeX was about equivalent to that used for the corresponding object in Inkscape. But the advantage of this version is that you can now have a template that is useful to generate similar objects. The lower scale can simply be removed by deleting the corresponding rows. The advantage of this approach is in the ability to resume the old drawing and modify it as a function of any corrections that such a complex gauge may require. This tool has several problems, such as the numbering that needs to be radial, and therefore require a rotation. The secondary scale which has its own radial numbering that does not follow the position angle, but a different scale.

### Let's proceed with order

Everything I wrote down to "\ begin {document}" is the same as the previous document, but there are 2 commands: "\tikzset{font={\fontsize{18pt}{10}\selectfont}}" as I used a different method of font size declarations by exploiting the fact that I do not have to change the scale. This also has the effect of removing the scale command as the gauge has a circular shape, so the X and Y axes have the same scale, This causes the "\begin{tikzpicture}[xscale=0.05]" command simply become "\begin{tikzpicture}"
The draw command change for polar coordinates:

\draw[ultra thick] (\a:5.6) -- (\a:6);


The variable \a is the angle with respect to the axis of the X (horizontal line). Two tick orders are printed, and then the 4 cardinal points following the anti-clockwise reference system of the Cartesian coordinates.

\draw (90: 4.5) node[rotate=0] {\Huge{N}};


Drawing with the polar coordinates means first inserting the angle, then the character ":" (instead of the "," character) and then an expressed distance of default in cm, or in millimeters if the numeric value or a variable is followed by the "mm" symbol.
The attribute [rotate = ..] after node statement indicates the rotation of the box that contains a string of characters. Because the cardinal points have a much bigger and thicker font, I used the attribute "Huge". LaTeX considers the font size choice (remember that OCR-B has standard size 10) by inserting a variable attribute in place of a value that changes depending on the font size. This means that the system behaves exactly respect the conventions of style, really important because it is the method used to print everything from Gutenberg, Bodoni etc on. This is one of the incredible aspects of LaTeX that seems to be limited in the font size, but in fact follows the strict and general rules. That's why when you make a project with this method you get an immediate result very close to reality! In this philosophy is the power of the method.

% \documentclass{standalone} is particular class that non have a size, but the size is define from
% the document itself
\documentclass[tikz,margin=0pt]{standalone}
% \usepackage{tikz} is the package that contain the graphics command as \draw etc ...
% The package is describe in this document: https://www.sharelatex.com/learn/TikZ_package
\usepackage{tikz}
% If the graduate dials is for analogical gauges period 50-70 years, this font is ok
% OCR is open-source package deposited in the CTAN repository: https://www.ctan.org/pkg/ocr-b
% Opentype can be used on Linux and Mac machines
% (I do not know if it's possible in Windows, but I think of it),
% https://www.ctan.org/tex-archive/fonts/ocr-b-outline
\usepackage{ocr}
% Defines the font size to use, the first number defines the font size,
% the second number the dimensional family from which the font is taken.
% It can be assumed that there are differences between a dimensional family 10 and a 12 dimensional font.
\begin{document}
% The link OCR package documentation is this: http://ctan.mirror.garr.it/mirrors/CTAN/macros/latex/contrib/ocr-latex/ocr.pdf
% \ocrfamily - Normal font family
% \ocrnegfamily - Family negative fonts
{\ocrfamily
\begin{tikzpicture}
%1° Rays
\foreach \a in {0, 5,...,355}
\draw[ultra thick] (\a:5.6) -- (\a:6);
%5° Rays
\foreach \a in {0, 10,...,359}
\draw[ultra thick] (\a:5.4) -- (\a:6);
%10° Rays
\foreach \a in {0, 30,...,359}
\draw[ultra thick] (\a:5.2) -- (\a:6);
%Angle labels
\foreach \a in {30, 60, 120, 150, 210, 240, 300, 330}
\pgfmathtruncatemacro\result{(360 - \a)/10}
\draw (\a + 90: 4.5) node[rotate=\a] {\LARGE\result};
% Wind rose labels
\draw (90: 4.5) node[rotate=0] {\Huge{N}};
\draw (360: 4.5) node[rotate=270] {\Huge{E}};
\draw (270: 4.5) node[rotate=180] {\Huge{S}};
\draw (180: 4.5) node[rotate=90] {\Huge{W}};
\foreach \b in {-40,-38,...,40}
\edef\c{-90 - \b * 1.38}
\draw[ultra thick] (\c:6.5) -- (\c:6.8);
\foreach \b in {-40,-30,...,40}
\edef\c{-90 - \b * 1.38}
\draw[ultra thick] (\c:6.5) -- (\c:7);
\foreach \b in {-40,-30,...,40}
\edef\c{-90 - \b * 1.38}
\pgfmathtruncatemacro\result{abs(\b)}
\draw (\c:6.2) node[rotate=\c+90] {\footnotesize\result};
\end{tikzpicture}
}
\end{document}


## Circular graduate dials as editing the previous one

Finish work example of est Graduate dials for PHI Wind

If you look at this code it is virtually identical to the previous one, the lines that defined the graduated secondary dial have been eliminated. The implementation time of this new version was therefore a few minutes since we were based on the previous element.
It is interesting to make some changes in the code to implement some parameter assignments in order to be able to easily modify this type of graduate dials. I also wanted to insert a colored arc, which is not present in the original instrument, but its construction technique is useful for other gauges that have colored arc.

### Creating parametric values

The command to use is similar to macro definition commands for other programming languages or application software:

\newcommand\posWindRose{2.8}


\newcommand defines a macro type command, followed by the name of the macro that begins with the character "\". For many who are accustomed to XML, the compactness of the LaTeX code can give nausea, but it is a typical feature of the languages of the 70's and 80's when they were to be run on machines with little memory. But this essential feature of programming language is certainly a great tool to quickly build a document, thus increasing the author's productivity.
Braces are the command that can be a value or an expression. Expressions can include other macro commands, as can be seen in the fourth row. Mathematical expressions in LaTeX can be very complex and include all the functions of a good scientific language. In the example I used only algebraic operations, but there are also transcendental, trigonometric, logarithmic functions etc. This allows inserting in place of the values, the expressions that generate them.

### Insert a colored arc

\begin{tikzpicture}
...
\coordinate (c1) at (0,0);
\draw[fill=yellow, draw=none]
($(c1) + (270:\arcRadius-\graduateInternaThick)$)
($(c1) + (300:\arcRadius)$)
\draw[fill=red, draw=none]
($(c1) + (45:\arcRadius-\graduateThick)$) arc (45:270:\arcRadius-\graduateThick) --
($(c1) + (270:\arcRadius)$) arc (270:45:\arcRadius) -- cycle;
...
\end{tikzpicture}


The method is to draw two arcs and two straight lines connecting them to the edges and then fill the whole with a color. The reason is that in TiKz there is no function to draw a bow directly, of course it is possible to realize it, but it is not said that in such simple cases it is useful. Therefore it is using TikZ like a plotter that traces the edge of the figure we want to achieve, in this way it is possible to make special effects such as arc segments which reduce or increase their thickness, as we shall see in another example later.
The parameter c1 defines the arc center that uses the \coordinate function, which is needed to have a center of arc independent of the starting point, in fact defining the center of a circle is simple, but an open figure like an arc is much less! Therefore, the calculation $(c1) + (270: \arcRadius-\graduateInternaThick)$ is used to compute the center of the arc having coordinates (0,0).

\coordinate (c1) at (0,0);


The second part arc (270:300:\arcRadius-\graduateInternaThick) draws an arc starting at 270 ° and ending at 300 °, remembering that in the Cartesian reference system the angle 0 ° corresponds to the horizontal axis of X and the rotation is anti-clockwise. As is evident the radius of this arc is defined by this expression: \arcRadius-\graduateInternaThick
The "--" indicates that you draw a line beginning at the end of the arc and arrives at the beginning of the next arc that this time will proceed in the opposite direction, and then close the figure.
The expression ($(c1) + (300:\arcRadius)$) define a new center where finish the line and restar the return arc as describe by this expression: arc (300:270:\arcRadius), it is important to note that now the system draws the arc in the opposite direction, ie from 300 ° to 270 ° with a different radius defined by the variable: \arcRadius. Finally, you must enter the closing line: "--".
Once the shape to be drawn is defined, we can color it with the color (fill=color parameter) and define the edge ('draw = ...), if the edge parameter is assigned none the edge will not be drawn.

#### A note about units of measurement

When a numeric value is expressed in our format, it is assumed that it is in "cm", but it can be prefigured in a different unit of measurement, for example "mm", just place the relative unit at its numeric value of measure adopted. For instance, you can write 1 to indicate 1 cm or the equivalent value in mm: 10mm[5], as for example the typographical point ( pt = 1/72 inches).

#### A note about the coordinate system adopted in LaTeX and Tikz:

LaTeX and TiKz Coordinates System[6]

The definition of the arc requires some attention as the center of rotation needs to be defined, if it were placed (0,0) the center would coincide with the center of the Cartesian axes (Latex uses Cartesian notation, that is, the angles are anti-clockwise and the angle zero corresponds to the horizontal axis of the X)[7].A purely Cartesian reference system requires some attention for those who commonly use the reference system used for CAD or other graphical programs (lower Y, clockwise angles). Defines the starting point to begin drawing the arc, the point is localized starting from the center in Cartesian coordinates (<X>,<Y>) and moving from this point to a new point defined this time with polar coordinates (<angle>: <radius>), as can be seen from the command executed to assign the first arc point: ...(c1) + (270:\arcRadius-\graduateInternaThick)...
The power and flexibility of TiKz language can sometimes be baffled, but it is the intrinsic force of a powerful and extremely synthetic language. It is clearly possible to mix different types of references (Cartesians and Poles), different units of measurement, and perform algebraic, trigonometric calculations and many other types of functions on them. Often TiKz is used along with another powerful language for GNUPLOT[8] statistical graphics, which completely integrates with TiKz and then LaTeX.

### The complete code

% Adriano Bassignana nov 2017
% Program for creating a linear index useful for the construction of a compass on a conical support
% The program can be modified and adapted for the construction of other types of numeric indexes.
% The font used is OCR-B which allows to have alphabetic and numeric symbols very similar
% to those used in analogue flight gauges in the 50s and 80s
% You must have installed OCR-B in OTF format that has a GPL-2 and later compatible license.
% The font is present in the texlive-fonts-extra package
%
% Explanation:
%
% \documentclass{standalone} is particular class that non have a size, but the size is define from
% the document itself
%%\documentclass[tikz,margin=0pt]{standalone}
% This command permit the direct file conversion from PDF to png or svg
% {outfile=test.png} the conversion is from pdf to png with background transparent layer
% {outfile=test.svg} the conversion is from pdf to svg but as only raster format
\documentclass[tikz,margin=0pt, convert={outfile=test.png}]{standalone}
% \usepackage{tikz} is the package that contain the graphics command as \draw etc ...
% The package is describe in this document: https://www.sharelatex.com/learn/TikZ_package
% If the "tikz" package is define as option on \documentclass is not necessary define this option
\usepackage{tikz}
% A TiKz library to extend math functions
\usetikzlibrary{calc}
% If the graduate dials is for analogical gauges period 50-70 years, this font is ok
% OCR is open-source package deposited in the CTAN repository: https://www.ctan.org/pkg/ocr-b
% Opentype can be used on Linux and Mac machines
% (I do not know if it's possible in Windows, but I think of it),
% https://www.ctan.org/tex-archive/fonts/ocr-b-outline
\usepackage{ocr}
\tikzset{font={\fontsize{9pt}{10}\selectfont}}
% Wind Rose position pram
\newcommand\posWindRose{2.8}
% Defines the font size to use, the first number defines the font size,
% the second number the dimensional family from which the font is taken.
% It can be assumed that there are differences between a dimensional family 10 and a 12 dimensional font.
\begin{document}
% The link OCR package documentation is this:
% http://ctan.mirror.garr.it/mirrors/CTAN/macros/latex/contrib/ocr-latex/ocr.pdf
% \ocrfamily - Normal font family
% \ocrnegfamily - Family negative fonts
{\ocrfamily
\begin{tikzpicture}
% Arc application as example:
% https://tex.stackexchange.com/questions/66216/draw-arc-in-tikz-when-center-of-circle-is-specified
\coordinate (c1) at (0,0mm);
\draw[fill=yellow, draw=none]
($(c1) + (270:\arcRadius-\graduateInternaThick)$)
($(c1) + (300:\arcRadius)$)
\draw[fill=red, draw=none]
($(c1) + (45:\arcRadius-\graduateThick)$) arc (45:270:\arcRadius-\graduateThick) --
($(c1) + (270:\arcRadius)$) arc (270:45:\arcRadius) -- cycle;
%2° Rays
\foreach \a in {0, 2,...,358}
\draw[line width=0.3mm, cap=round]
%10° Rays
\foreach \a in {0, 10,...,350}
\draw[line width=0.6mm, cap=round]
%Angle labels
\foreach \a in {30, 60, 120, 150, 210, 240, 300, 330}
\pgfmathtruncatemacro\result{(360 - \a)/10}
% Wind rose labels
% Insert the label
\draw (90: 0.8) node{WIND UNIT};
\end{tikzpicture}
}
\end{document}


## Make experiments

FIAT G91 Compass gauge and S.F.O.M. collimator example of vary graduate dial

To make the tests the simplest solution is to use a LaTeX version already on the Web. LaTeX is not a graphical environment, it allows you to create great websites with very well-made editors and excellent preview. I've done tests on this site: https://it.sharelatex.com/ You can sign up for them, open a blank document, and copy the contents of the example in this guide. Then click the [Recompile] button and almost instantly you will see the result of your effort on the right. The site contains many guides that explain how LaTeX and its many commands work. Then you can download the PDF file and edit it to convert it to PNG with the right dimension using a program like GIMP that can import the PDF correctly.

LaTeX is a program that can be run virtually by virtually any operating system on this planet and PCs that are not very powerful either. LaTeX has always been exactly the same graphic result on any machine where it is run and at any time the code has been written. For LaTeX there are no backward versions, everything is complete backward compatible! So who wants to develop his gauge or other graphic elements, manuals, maps etc. it is always advised to attach a copy of the original LaTeX so that anyone who modifies an aircraft may also modify the graphic elements that make up the aircraft.

## LaTeX installing

If you want to use LaTeX not only to do small jobs, as I explained in this guide, but also documents (maybe your FGFS manuals for your plane) you can follow many guides to explain how to do it. I remind you that LaTeX is an absolutely professional program and its complete installation requires a space of several GBs! Anyway, I think the satisfaction of having a video editing and composition system like LaTeX is well worth the effort of a not banal installation.

Here's an extra simple guide to installing LaTeX: https://www.latex-tutorial.com/installation/

These are definitely more complete guides:

For Windows:

For Linux:

For publishers the choice is vast, in Linux I use TeXstudio that I find it really good, or who uses KDE can try Kile is cute and well done, but maybe TeXstudio is really more powerful.

If you want to use a word processing system that is more like Write or Word, you can use LyX (https://www.lyx.org/) a program I have been using for more than 10 years and with which I could do wonderful things . However LyX always produces a LaTeX document.

## References

1. I think it's useful to read this Wikipedia article before starting to work with this technique to get a general idea of the program: https://en.wikipedia.org/wiki/LaTeX
2. LaTex is a programming language, such as NASAL, XML, etc ... LaTeX is not structured as XML since, at the time of implementation (1975), XML was not yet conceived and in any case the XML it would be too long-winded language to be used directly as an editor / formatter of a text. At this link there is a simple guide for those who want to learn LaTeX: Learn LaTeX in 30 minutes (From Sharelatex)
3. The graphic engine TikZ is explained in many articles, one of the most synthetics I have found is this: https://it.sharelatex.com/learn/TikZ_package
4. https://ctan.org/
5. Graphics with TikZ (Andrew Mertz and William Slough) Pag. 12 : https://www.tug.org/pracjourn/2007-1/mertz/mertz.pdf
6. Example of coordinates in the LaTeX: https://tex.stackexchange.com/questions/155181/coordinate-system-in-latex-with-tikz
7. An example for GNUPLOT basics integration is show in this article: http://www.texample.net/tikz/examples/gnuplot-basics/