The creation of their intricate styles for LaTeX

History


If you regularly create Teh e uniform documents, the creation of his style can significantly speed up the work.

/ > My regular documents is the creation of leaflets with tasks for students. Ready they look as follows: PNG or PDF (and so, so or so)
Almost all of the design here (and also a separate sign for the results) is automatically created.
(if it is necessary for someone, you can give a package with documentation and examples of usage)

Different "tricks" to create your own style I would like to share.
If you are not the subject of the creation of their team, it is best to read Lviv or something like that.


the

Commands with Russian letters (and how to use Russian in the formulas and how to add Russian in pdf)



It is often convenient to create a team consisting of Russian letters. For example, to write
the
Curve is called the envelope of the if ...


A barrier to the establishment of such teams is that Those by default, considers the Russian letters are not quite letters (they have the wrong catcode (see the Whip)).
To explain Tehu your desire, you need to use either a large but understandable
the

\catcode156=11\catcode201=11\catcode212=11\catcode223=11\catcode234=11\catcode245=11
\catcode188=11\catcode202=11\catcode213=11\catcode224=11\catcode235=11\catcode246=11
\catcode192=11\catcode203=11\catcode214=11\catcode225=11\catcode236=11\catcode247=11
\catcode193=11\catcode204=11\catcode215=11\catcode226=11\catcode237=11\catcode248=11
\catcode194=11\catcode205=11\catcode216=11\catcode227=11\catcode238=11\catcode249=11
\catcode195=11\catcode206=11\catcode217=11\catcode228=11\catcode239=11\catcode250=11
\catcode196=11\catcode207=11\catcode218=11\catcode229=11\catcode240=11\catcode251=11
\catcode197=11\catcode208=11\catcode219=11\catcode230=11\catcode241=11\catcode252=11
\catcode198=11\catcode209=11\catcode220=11\catcode231=11\catcode242=11\catcode253=11
\catcode199=11\catcode210=11\catcode221=11\catcode232=11\catcode243=11\catcode254=11
\catcode200=11\catcode211=11\catcode222=11\catcode233=11\catcode244=11\catcode255=11

or more compact, but not quite obvious (taken from style russlh.sty)
the
\def\reserved@a#1#2{\@tempcnta#1\relax\@tempcntb#2\relax\reserved@b}
\def\reserved@b{\ifnum\@tempcnta>\@tempcntb\else\reserved@c\@tempcnta\advance\@tempcnta\@ne\expandafter\reserved@b\fi}
\def\reserved@c#1{\catcode#1=11\relax}
\reserved@a{192}{223} % A-z
\reserved@a{224}{255} % a-z
\catcode156=11 % E
\catcode188=11 % e


After that problems with Russian letters in commands disappear.

Russian language and formulas

If you want to use Russian letters as Russian letters in formulas, then save the package mathtext.

Russian language and for PDF

If you want to get the proper Russian letters when searching the pdf, it will help the cmap package. However, there is a better solution: you can proincluding file glyphtounicode.tex with unicod codes a significant part of the characters, then in the finished pdf will look for (and copy-paste) the Greek letters and many mathematical icons.

the

Complex parameters in environments and styles (and how to put an arbitrary size, and line spacing)



How to make your environment or your style so that in the settings you can specify:
the
[Par1=Value1, Par2=Value2, dump]
?

It would be very convenient in many cases.

The answer gives the keyval package.sty.

What to do

First, we plug style:
the
\usepackage{keyval}


Then we can determine how to handle the keys:
the

\define@key
{Group name key}
{the name of the specific key}
[default value] (if  value  is not passed, and if its value is simply not necessary)
{how to process value}


Now we call the team that rasarit the text for each variable correctly will fulfill what was written in the corresponding \define@key
the

\setkeys
{Group name key}
{parameters that need to parse}


Example for the environment


So, for example, we want to create the environment within which the spaces between lines are specified explicitly, and select the font size. (Thanks To Yandex.The abstracts for the given text)
Code:

\documentclass[12pt]{article}
\usepackage[textwidth=5cm]{geometry}
\usepackage[T2A]{fontenc}
\usepackage[cp1251]{inputenc}
\usepackage[russian]{babel}
\usepackage{keyval}
\sloppy


\makeatletter
\newlength{\wid} % variable -width-block
\newtoks{\fnt} % variable --- the font size
\newlength{\skp} % variable --- the spaces between lines

\define@key{key}{font}[12]{\fnt={#1}}
% define the font key, the value written in the variable (if the value was not passed, 12)
\define@key{key}{skip}{\skp=#1}
\define@key{key}{width}{\wid=#1}

\newenvironment{test}[1]%
% define the environment with one parameter
{\setkeys{key}{#1}%
% parsim settings
\begin{minipage}{\wid}
% starting block to the specified width
\fontsize{\the\fnt}{\skp}\selectfont
% set the desired font size and line spacing
}%
{\par\end{minipage}}
% end block
\makeatother
% @ is again the command

\begin{document}

\begin{test}{font=6,skip=14pt,width=5cm}
Infinitely small value is negative. Connected set, therefore, rapidly enhances the determinant of a system of linear equations, which is not surprising. Dirichlet integral, of course, attracts the increasing sheet Mobius, clearly demonstrating all the nonsense of the foregoing. Sufficient condition of convergence of monotone.
\end{test}

\bigskip

\begin{test}{width=7cm,skip=13pt,font}
Infinitely small value is negative. Connected set, therefore, rapidly enhances the determinant of a system of linear equations, which is not surprising. Dirichlet integral, of course, attracts the increasing sheet Mobius, clearly demonstrating all the nonsense of the foregoing. Sufficient condition of convergence of monotone.
\end{test}


\end{document}

The result:
image

(about the \fontsize and \selectfont read in the Whip or Lviv)

Sophisticated options of style

Now a more difficult task to make such parameters were in style.
To solve the problem, I had to learn how to construct style geometry.sty.

Here all is very similar, but you need to add some code that will force you to parse the parameters at the beginning of the style. Here is an example, it will be enough:

Example (and also how to make your team the mag to work correctly with fields in a document)


test.sty


\ProvidesPackage{test.sty}
\RequirePackage[T2A]{fontenc}
\RequirePackage[cp1251]{inputenc}
\RequirePackage[russian]{babel}
\RequirePackage{keyval}

% As before, define how to handle the keys
\define@key{key}{mag}{\mag#1}

%this code actually parses the input parameters of the style
\let\@tempa\@empty%
\edef\@tempa{\@ptionlist{\@currname.\@currext}}%
\@for\CurrentOption:=\@classoptionslist\do{%
\@ifundefined{KV@#2@\CurrentOption}{}{\edef\@tempa{\@tempa,\CurrentOption,}}}%
\edef\@tempa{\noexpand\setkeys{key}{\@tempa}}%
\@tempa%
\AtEndOfPackage{\let\@unprocessedoptions\relax}%

% And this is for that field did not go either in dvi or in pdf.
% The fact that dvi and pdf sometimes use their variables 
% and some are measured in scaled units (no true), and some --- on the contrary. 
% Everything is crawling.
\global\setlength\paperheight {297truemm}%
\global\setlength\paperwidth {210truemm}%
\global\setlength\pdfpageheight{297truemm}%
\global\setlength\pdfpagewidth {210truemm}%
\global\setlength\textheight {260truemm}%
\global\setlength\textwidth {180truemm}%
\global\setlength\hoffset {-1truein}%
\global\setlength\voffset {-1truein}%
\global\setlength\pdfhorigin {1truein}%
\global\setlength\pdfvorigin {1truein}%
\global\setlength\oddsidemargin{15truemm}%
\global\setlength\topmargin {5truemm}%
\global\setlength\leftskip {0truemm}%
\global\setlength\rightskip {0truemm}%

test.tex


\documentclass[12pt]{article}
\usepackage[mag=2000]{test}

\begin{document}

Voila!

\end{document}

(team mag that allows to arbitrarily scale the document is very good. But it must be called as early as possible. With it there are many glitches for example on 1cm or 1in scaling will not affect 1truecm or 1truein — no. Therefore, in all the fields you need to use a true-one, and in all other places — the usual. Because of this, the geometry package with the mag not working properly. In addition, for the sizes of pages (and changes) to a pdf and dvi use different values (for example, paperheight and pdfpageheight), which leads to even more problems. The code takes into account all of them)

What else?



Over 8 + years of using Tex and create your own style, I have accumulated quite a lot of different tricks above and all non-trivial moments of bad literature.
If there is interest, it can also illuminate.

    the
  1. Create portable assemblies and configure WinEdt (my build on torrents)
  2. the
  3. configure WinEdt for forward and backward search in PDF (about dvi it is possible to forget) (on Habre about it already wrote
  4. the
  5. Create commands that "analyze" the structure of the document on the fly — for example, automatic creation of complex conduits and write some data in external files on the fly (for example, we have on-the-fly, a special xml, which is then used to e-conduit)
  6. the
  7. Processing and execution of perl, python, metapost or any third-party pieces of code on the fly
  8. the
  9. As a result, sloppy compiling someone else's document, you can, say, delete some data, run virus programs, etc., etc. (example ;-)
  10. the
  11. Creation and adding pictures, graphs, etc. directly to Those in metapost, IPE, GeoAlgebra, etc. (it has also been time, two, three, but the topic is immense.
Article based on information from habrahabr.ru

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

Approval of WSUS updates: import, export, copy

Kaspersky Security Center — the fight for automation

The Hilbert curve vs. Z-order