Draw Circle Latex After Itemize
Documents produced with the commands you lot accept learned up to this point will look acceptable to a large audience. While they are non fancy-looking, they obey all the established rules of proficient typesetting, which will make them like shooting fish in a barrel to read and pleasant to look at. However, there are situations where LaTeX does non provide a command or surroundings that matches your needs, or the output produced past some existing command may not run across your requirements.
In this affiliate, we volition try to give some hints on how to teach LaTeX new tricks and how to make information technology produce output that looks dissimilar from what is provided past default.
LaTeX is a fairly loftier-level language compared to Patently TeX and thus is more limited. The next affiliate will focus on Plain TeX and will explain advanced techniques for programming.
New commands Edit
To add your own commands, use the
\newcommand { \proper name }[num]{definition} command. Basically, the command requires 2 arguments: the name of the command you want to create (preceded by a backslash), and the definition of the command. Note that the command proper name tin can but need not exist enclosed in braces, every bit yous like. The num statement in square brackets is optional and specifies the number of arguments the new control takes (upwardly to ix are possible). If missing it defaults to 0, i.due east. no argument allowed.
The post-obit two examples should help you to get the thought. The starting time instance defines a new control called \wbal that will print "The Wikibook about LaTeX". Such a command could come in handy if you had to write the championship of this volume over and once more.
\newcommand { \wbal }{The Wikibook about \LaTeX } This is ''\wbal'' \ldots {} ''\wbal'' | This is "The Wikibook about LaTeX" … "The Wikibook almost LaTeX" |
The side by side example illustrates how to define a new control that takes 1 statement. The #1 tag gets replaced by the statement yous specify. If you wanted to use more than one argument, use #ii and then on, these arguments are added in an extra set of brackets.
\newcommand { \wbalsup }[1] { This is the Wikibook nearly LaTeX supported by #1} \newcommand { \wbalTwo }[2] { This is the Wikibook most LaTeX supported by #1 and #2} % in the document trunk: \begin {itemize} \detail \wbalsup {Wikimedia} \particular \wbalsup {lots of users!} \item \wbalTwo {John Doe}{Anthea Smith} \end {itemize} |
|
Proper noun your new command \wbalTwo and not \wbalii as digits cannot be used to name macros — invalid characters will error out at compile-time.
LaTeX will non allow you to create a new command that would overwrite an existing one. But in that location is a special command in example you explicitly want this: \renewcommand . It uses the aforementioned syntax every bit the \newcommand command.
In certain cases you lot might as well desire to use the \providecommand command. It works similar \newcommand , but if the command is already defined, LaTeX will silently ignore the new control.
With LaTex2e, information technology is also possible to add together a default parameter to a command with the post-obit syntax:
\newcommand {name}[num][default]{definition} If the default parameter of \newcommand is present, then the first of the number of arguments specified by num is optional with a default value of default; if absent, and then all of the arguments are required.
\newcommand { \wbalTwo }[two][Wikimedia]{ This is the Wikibook about LaTeX supported by {#1} and {#2}!} % in the document body: \brainstorm {catalog} \detail \wbalTwo {John Doe} \particular \wbalTwo [lots of users] {John Doe} \end {catalog} |
|
- Note
- When the command is used with an explicit commencement parameter information technology is given enclosed with brackets (here "[lots of users]").
Here is a common example: if you are writing a book about Mathematics and yous have to use vectors, y'all have to determine how they will look. There are several different standards, used in many books. If a is a vector, some people like to add an arrow over information technology ( ), other people write it underlined ( a ); another common version is to write it bold (a). Permit u.s.a. assume you lot desire to write your vectors with an arrow over them; then add the following line in your mystyle.sty.
\newcommand { \myvec }[1]{ \vec {#1}} and write your vectors inside the new \myvec {...} control. You tin telephone call it as you wish, merely yous'd ameliorate choose a short proper name because you will probably write it very often. Then, if you lot alter your mind and y'all desire your vectors to look differently you only accept to alter the definition of your \myvec {...} . Utilise this approach whenever you lot can: this volition relieve yous a lot of time and increase the consistency of your certificate.
DeclareRobustCommand Edit
Some commands are fragile, that is they fail in some environments. If a macro works in body text but not in (for case) a effigy caption, it's worth trying to replace the \newcommand { \MyCommand }... proclamation with \DeclareRobustCommand { \MyCommand }... in the preamble. This is particularly true for macros which, when expanded, produce text that is written to a .aux file.
New environments Edit
But as with the \newcommand command, there is a command to create your own environments. The \newenvironment command uses the post-obit syntax:
\newenvironment {name}[num][default]{before}{afterwards} Again \newenvironment can have an optional statement. When the \begin {proper name} control (which starts the environment) is encountered, the textile specified in the earlier argument is candy earlier the text in the environs gets processed. The cloth in the after argument gets processed when the \stop {name} command (which ends the environment) is encountered.
The optional num and default arguments are used the same mode as in the \newcommand command. LaTeX makes certain that you practise not define an environment that already exists. If you ever want to change an existing environs, you can use the \renewenvironment control. It uses the aforementioned syntax equally the \newenvironment control.
The example beneath illustrates the usage of the \newenvironment command:
\newenvironment {king} { \rule {1ex}{1ex} \hspace { \stretch {1}} } { \hspace { \stretch {1}} \rule {1ex}{1ex} } \begin {king} My humble subjects \ldots \end {king} |
Edit
When creating a new surroundings you may easily get bitten past extra spaces creeping in, which can potentially take fatal effects. 1 instance is when you want to create a title surroundings which suppresses its own indentation as well as the one on the following paragraph. The \ignorespaces control in the begin block of the surroundings will arrive ignore whatsoever space after executing the begin block. The stop block is a fleck more than tricky every bit special processing occurs at the end of an environment. With the \ignorespacesafterend LaTeX volition issue an \ignorespaces after the special 'end' processing has occurred.
\newenvironment {simple} % { \noindent } % { \par\noindent } \begin {simple} Come across the space\\to the left. \end {uncomplicated} Same\\here. | See the infinite to the left. Same here. |
\newenvironment {right} % { \noindent\ignorespaces } % { \par\noindent % \ignorespacesafterend } \begin {correct} No space\\to the left. \end {correct} Same\\here. | No space to the left. Same here. |
Also, if you're still having problems with extra space being appended at the end of your surround when using the \input for external source, make certain there is no space betwixt the showtime, sourcing, and end of the environment, such equally:
\brainstorm {correct} \input {somefile.tex} \finish {correct} or
\begin {correct} % \input {somefile.tex} % \finish {correct} Declare commands inside new environs Edit
New commands can be declared within newenvironment. Commands alleged within the newenvironment refer to their arguments by doubling the # graphic symbol. In the post-obit example, a new surround is declared along with a nested command:
\newenvironment {topics}{ \newcommand { \topic }[2]{ \item {##ane / ##2} } Topics: \begin {itemize} } { \end {itemize} } If, by mistake, the arguments passed to the \topics macro are defined with a single # character, the following error message will be thrown:
! Illegal parameter number in definition of \topics.
Extending the number of arguments Edit
The xkeyval packages will permit you define central/value options for commands.
\mycommand [key1=value1, key3=value3] {some text} The package is quite complete and documentation is exhaustive. We recommend that package developers read it. [1]
Let'south provide a elementary example[1]:
\usepackage {xkeyval} % ... \makeatletter \def\my@emphstyle#1{ \csname my@way@#1\endcsname } %% Predefined styles \providecommand\my@style@default{ \em } \providecommand\my@mode@bold{ \bfseries } \define@central{myemph}{lawmaking}{ % \def\my@emphstyle{#i} } \ascertain@key{myemph}{style}{ % \def\my@emphstyle{ \csname my@style@#1\endcsname } } \newcommand\setemph [1] { % \setkeys {myemph}{#1} } \renewcommand\emph [1] { % { \my@emphstyle #1} } \makeatother Something \emph {important} \setemph {mode=bold} Something \emph {important} \setemph {code=\Large\sffamily } Something \emph {important} Arithmetic Edit
LaTeX can manipulate numbers.
The calc bundle provides the common infix notation.
\usepackage {calc} % ... \newcounter {mine} \setcounter {mine}{2*17} \themine For high-precision computations, you can use the fp [two] package.
\usepackage {fp} % Clip \[ \FPmul\event { two }{ 7 } \FPclip\result\result 2 * seven = \result \] % Infix \[ \newcommand\consequence { 11 } \sqrt { \sin ( 2 + \outcome ) } \approx \FPeval\result {circular ( root ( ii ,sin ( effect + 2 . 5 )) , 2 ) } \result \] % Postfix \[ \FPupn\issue { 17 2 . five + 17 . 5 bandy - ii ane + * two swap / } % or \FPupn\event{2 17.5 17 two.5 + - 2 1 + * /} \FPclip\issue\consequence ( 17 + 2 . five - 17 . 5 ) * ( 2 + ane ) / 2 = \result \] % Loftier precision \[ \FPdiv\result { 17 }{ 7 } \frac { 17 }{ seven } \approx \FPtrunc\result\outcome { 3 } \result \] Conditionals Edit
LaTeX tin can use conditionals thanks to the ifthen package.
\usepackage {ifthen} % ... \ifthenelse { \equal { \myvar }{true} }{ This is true. }{ This is false. } FYI: For newer projects eastward-TeX is recommended[3], bachelor in LaTeX from etoolbox. See section 3.six of their manual.
Following a brusk example, a bool that switches its country every time it is used.[4]
\documentclass {article} \usepackage {etoolbox} \usepackage {parskip} \usepackage {tikz} \newbool {volt} \newcommand { \onoff }{ % \ifbool {volt}{ % \boolfalse {volt} \candleOn\infinite ON}{ % \booltrue {volt} \candleOff\infinite OFF} % } \newcommand { \candleOff }{ \tikz \draw (0,0) rectangle (.2,.viii);} \newcommand { \candleOn }{ \begin {tikzpicture} \draw (0,0) rectangle (.ii,.8);\draw [fill=orange] (.i,.9) circle [radius=.1];\stop {tikzpicture} } \brainstorm {certificate} \onoff\par \onoff\par \onoff\par \onoff\par \stop {document} Loops Edit
The PGF/TikZ extension provides the \foreach control.
\usepackage {tikz} % ... \foreach \i/\q in {wheat/50g, water/1L, yeast/2g}{ \noindent\i\dotfill\q\\ } If you are but using \foreach and non cartoon graphics, you may instead employ the pgffor package straight.
Alternatively you can check out the multido package.
Strings Edit
xstring provides a lot of features. From CTAN:
- testing a string's contents
- extracting substrings
- exchange of substrings
- string length
- position of a substring
- number of recurrences of a substring
Examples:
\usepackage {xstring} % ... \newcommand\mystr {Hello World!} The string ``\mystr'' has \StrLen { \mystr }{} characters. Predicate ``\mystr {} contains the discussion Hi'' is \IfSubStr { \mystr }{Hello}{true}{false}. LaTeX Hooks Edit
LaTeX provides ii hooks:
-
\AtBeginDocumentvolition let you specify a prepare of commands that will be executed when\begin {document}is met. -
\AtEndDocumentdoes the aforementioned for\end {document}.
This gives you some more flexiblity for macros. Information technology can be useful to override settings that get executed after the preamble. These hooks can be called several times. The commands will exist executed in the order they were fix.
For case, permit's supersede the folio numbers with oldstylenums:
\usepackage {textcomp} \AtBeginDocument { % % Make the folio numbers in text figures \let\myThePage\thepage \renewcommand { \thepage }{ \oldstylenums { \myThePage } } } There are too hooks for classes and packages. See Creating Packages.
Command-line LaTeX Edit
If y'all piece of work on a Unix-like Os, you might exist using Makefiles or any kind of script to build your LaTeX projects. In that connection information technology might exist interesting to produce different versions of the same document by calling LaTeX with command-line parameters. If you lot add the following construction to your document:
\usepackage {ifthen} %... % default value. \providecommand\blackandwhite {false} %... \ifthenelse { \equal { \blackandwhite }{true} }{ % "blackness and white" mode; exercise something.. }{ % "colour" style; practice something different.. } At present you tin phone call LaTeX like this:
latex '\providecommand{\blackandwhite}{true}\input{test.tex}' First the control \blackandwhite gets defined and then the actual file is read with input. By setting \blackandwhite to fake the color version of the certificate would be produced.
Notes and References Edit
- ↑ tex.stackexchange.com
- ↑ ctan.mackichan.com
- ↑ https://tex.stackexchange.com/questions/13866/why-is-the-ifthen-bundle-obsolete
- ↑ https://tex.stackexchange.com/a/232059/37907
brinkerhoffhiplace.blogspot.com
Source: https://en.m.wikibooks.org/wiki/LaTeX/Macros
Enregistrer un commentaire for "Draw Circle Latex After Itemize"