latex-algorithms
- 格式:pdf
- 大小:389.39 KB
- 文档页数:15
algorithm2e.sty—package for algorithmsrelease3.9(c)1996–2005Christophe Fiorio,LIRM Montpellier,FranceReport bugs and comments tofiorio@lirmm.fralgorithm2esty-annonce@lirmm.fr mailing list for announcementsalgorithm2esty-discussion@lirmm.fr mailing list for discussion∗†‡§¶ ∗∗††febuary102005Contents1Introduction2 2How to use it:abstract2 3Compatibility issues with other packages4 4Environments defined in the package4 5The options of the package4 6The macros provided with the package66.1Typesetting macros (6)6.2Restyling macros (7)7The predefined language keywords97.1To define your own language keywords (12)8Two complete examples178.1Algorithm2:disjoint decomposition (17)8.2Algorithm3:IntervalRestriction (19)9Other language predefined keywords219.1french keywords (21)9.2German keywords (22)9.3Portuguese keywords (24)9.4Some Czech keywords (25)10Known bugs25∗The author is very grateful to David Carlisle,one of the authors of the LaTeX Companion book,for his advices †Martin Blais(blais@IRO.UMontreal.CA)for his suggestions‡David A.Bader(dbader@)for his new option noend§Gilles Geeraerts(gigeerae@ulb.ac.be)for his new command SetKwIfElseIf¶Ricardo Fukasawa(fukasawa@)for the portuguese keywordsChristian Icking(christian.icking@fernuni-hagen.de)for the german translation of keywords∗∗Arnaud Giersch(giersch@icps.u-strasbg.fr)for his suggestions and corrections on SetKwComments††and the many users as Jean-Baptiste Rouquier(jean-baptiste.rouquier@ens-lyon.fr)for their remarks1IntroductionAlgorithm2e is an environment for writing algorithms in L A T E X2e.An algorithm is defined as a floating object likefigures.It provides macros that allow you to create different sorts of key words, thus a set of predefined key words is given.You can also change the typography of the keywords.You can subscribe to algorithm2e-announce mailing list to receive announcements about revisions of the package and to algorithm2e-discussion to discuss,send comments,ask questions about the package.In order to subscribe to the mailing lists you have to send an email to sympa@lirmm.fr with subscribe algorithm2e-announce Firstname Name orsubscribe algorithm2e-discussion Firstname Name in the body of the message.2How to use it:abstractYou must set\usepackage[options]{algorithm2e}before\begin{document}command.The available options are described in section5.The optional arguments[Hhtbp]works like those offigure environment.The H argument forces the algorithm to stay in place.If used,an algorithm is no more afloating object.Caution: algorithms cannot be cut,so if there is not enough place to put an algorithm with H option at a given spot,L A T E X will place a blank and put the algorithm on the following page.Here is a quick example1:\begin{algorithm}[H]\SetLine\KwData{this text}\KwResult{how to write algorithm with\LaTeX2e}initialization\;\While{not at end of this document}{read current\;\eIf{understand}{go to next section\;current section becomes this one\;}{go back to the beginning of current section\;}}\caption{How to write algorithms}\end{algorithm}which givesData:this textResult:how to write algorithm with L A T E X2einitialization;while not at end of this document doread current section;if understand thengo to next section;current section becomes this one;elsego back to the beginning of current section;endendAlgorithm1:How to write algorithms1For longer and more complexe examples see Section8Very Important:each line MUST end with\;only those with a macro beginning a block should not end with\;.Note then that you can always use the\;command in math mode to set a small space.The caption works as in afigure environment and is used by\listofalgorithms as a reference name for the list of algorithms.You can also use the title macro given with the package,but this macro doesn’t insert an entry in the list of algorithms.There are six text types in an algorithm environment:1.The keywords(Kw):Macros which usually indicate words of the language.Some arepredefined and given with the algorithm package.The user can define his own language keywords by using the different macros presented in section7.1(see below for a short,non exhaustive list).He can also define simple keywords with the\SetKw{Kw}{thetext}macro.2.The Functions:(Func)Macros defined by the user which denote local functions or otheralgorithms defined in the text.They are defined using\SetKwFunction{KwFn}{Fn}where\KwFn will be the macro and Fn the text printed.3.The Arguments(Arg):The arguments of the Kw or Func macros.4.The procedure and function name environment style(ProcNameSty):The type style ofthe caption of procedure and function environment.5.The arguments of procedure and function environments style(ProcArgSty):the type styleof the argument of procedure and function environments.6.Data(Data):A type of text different from the default.You can use it as you want,and canbe useful for example to emphasize a Data structure or denotes some important variables.They are defined with the help of the\SetKwData{KwDat}{data}macro,where\KwDat will be the macro and data the text printed.7.The text(the default):All the remaining text of the algorithm.Note that if you define macros outside the algorithm environment they are available in all the document and,in particular,you can use them inside all algorithms without redefining them.Be careful you can’t use macros beginning a block outside an algorithm environment.Here are some language keywords predefined in the package2:•\KwData{input},\KwResult{output},\KwIn{input},\KwOut{output}•\KwTo,\KwRet{[value]}•\Begin{block inside}•\eIf{condition}{then block}{else block},\If{condition}{then block}•\Switch{condition}{Switch block},\Case{a case}{case block},\Other{otherwise block}•\For{condition}{text loop}•\While{condition}{text loop}•\Repeat{end condition}{text loop}2See Section7for a complete list of all predefined macros such as\uIf,...3Compatibility issues with other packagesAt this time,release3.9has no known compatibility problem with other packages.Neverthe-less,when use with some packages,you need to specify some particular options,either from algorithm2e package or from the other packages.hyperref if you want to compile in L A T E X,you have to use it with naturalnames option.You don’t need to specify it if you compile with pdflatex.4Environments defined in the packageThis package provides4environments:algorithm:the main environment,the one you will used most of the time.algorithm*:same as the precedent,but used in a two columns text,puts the algorithm across the two columns.procedure:This environment works like algorithm environment but:•the ruled(or algoruled)style is recommended.•the caption now writes Procedure name...•the syntax of the\caption command is restricted as follow:you MUST put a namefollowed by2braces like this“Name()”.You can put arguments inside the braces andtext after.If no argument is given,the braces will be removed in the title.•label now puts the name(the text before the braces in the caption)of the procedureor function as reference(not the number like a classic algorithm environment).procedure*:same as the precedent,but used in a two columns text outs the procedure across the two columns.function:as the precedent but with Function instead of procedure in the title.function*:same as the precedent,but used in a two columns text outs the function across the two columns.5The options of the packagealgo2e:changes the name of environment algorithm into algorithm2e and so allows to use the package with some journal style which already define an algorithm environment.Changes also the command name for the list of algorithms,it becomes\listofalgorithmesslide:require package color.Hack for slide class in order to have correct margins.english:the default.french:to have for example algorithme:instead of algorithm:.german:to have for example Prozedur:instead of procedure:.portugues:to have for example Algoritmo:instead of algorithm:.czech:to have for example Algoritmus:instead of algorithm:.figure:algorithms are put in classicalfigures and so are numbered asfigures and putted in the \listoffigures.algopart:algorithms are numbered within part numbers.algochapter:algorithms are numbered within chapter numbers.algosection:(default)algorithms are numbered within section numbers.boxed:to have algorithms enclosed in a box.boxruled:to have algorithms enclosed in a box and caption above and boxed to.ruled:to have algorithms with a line at the top and the bottom.Note that the caption is not centered under the algorithm anymore but is set at the beginning of the algorithm.algoruled:as above but with extra spaces after the rules.plain:the default,with no feature.lined:\SetLine becomes the default,see section6.2for explanations about the\SetLine macros.vlined:\SetVline becomes the default,see section6.2for explanations about the\SetVline macros.noline:\SetNoline becomes the default,see section6.2for explanations about the\SetNoline macros.linesnumbered:lines of the algorithms are numbered except for comments and input/output (KwInput and KwInOut).You must use\nllabel{label}to label thoses lines.linesnumberedhidden:lines of the algorithms are numbered as linesnumbered but numbers are not shown.\showln and\showlnlabel{label}show the number on line they are put.commentsnumbered:makes comments be numbered if numbering is active.inoutnumbered:makes data input/output be numbered if numbering is active. titlenumbered:\Titleofalgo{title}prints Algorithm n:thetitle where n is the counter of the algo.Beware:\Titleofalgo don’t insert an entry in the list of algorithms.So do not use \Titleofalgo with a caption.Both increment the counter of the algorithms. titlenotnumbered(default)the macro\Titleofalgo{title}doesn’t number the algorithm.resetcount the line numbers are reset to0at the beginning of each algorithm(by default).noresetcount the contreverse of the precedent.To reset the line counter to0do: \setcounter{AlgoLine}{0}algonl the line numbers will be prefixed with the number of the current algorithm.Take care to set the caption of the algorithm at the beginning of the environnement,else you will have the precedent algorithm number as the current one.longend the end keyword are longer and different for each macro.For example endif for a if-then-else macro.shortend the“end keyword”of the macros is just end(default).noend the“end keyword”of the macros is not printed.dotocloa adds an entry in the toc for the list of algorithms.This option loads package tocbibind if not already done and so list offigures and list of tables are also added in the toc.If you want to control which ones of the lists will be added in the toc,please load package tocbibind before package algorithm and give it the options you want.scright(default)right justified side comments(side comments areflushed to the righr)scleft left justified side comments(side comments are put right after the code line)fillcomment(default)end mark of comment isflushed to the right so commentsfill all the width of textnofillcomment end mark of comment is put right after the comment6The macros provided with the package6.1Typesetting macros\;marks the end of a line.Don’t forget it!.By default,it prints a‘;’.You can change this with\dontprintsemicolon.\Titleofalgo{thetitle}prints:“Algorithm n◦:thetitle”in the typography and size defined by \SetTitleSty.Puts a vertical space below.Beware:\Titleofalgo doesn’t insert an entry in the list of algorithms.So don’t use \Titleofalgo with\caption.Both increment the counter of the algorithms.note:with the french option prints Algorithme n◦:\listofalgorithms inserts the list of all algorithms having a caption.\BlankLine prints a blank line.In fact puts a vertical space of one ex.\Indp indents plus→the text is shifted to the right.\Indm indents minus→the text is shifted to the left.\nllabel{label}macro for labelling lines when auto-numbering is active.\nl numbers the line:must begin the line.\lnl{label}numbers and labels the line:must begin the line.So you can refer to the number of the line by the following command:\ref{label}\nlset{}and\lnlset{}{}work as\nl and\lnl{}except that the additional argument is the number(text)to put at the begin of the line.\showln shows number of the line when linesnumberedhidden is activated.\showln{label}same as precedent but with a label.\KwSty{<text>}set<text>in keyword type style.\FuncSty{<text>}set<text>in function type style.\ArgSty{<text>}set<text>in argument type style.\DataSty{<text>}sets<text>in data typography.\CommentSty{<text>}sets<text>in comment typography.\AlFnt is used at the beginning of the body of algorithm in order to define the fonts used for typesetting algorithms.You can use it elsewhere you want to typeset text as algorithmFor example you can do\SetAlFnt{\small\sf}to have algorithms typeset in small sf font.Default is nothing so algorithm is typeset as the text of the document.\AlCapFnt is used at the beginning of the caption in order to define the fonts used for typesetting algorithms.You can use it elsewhere you want to typeset text as algorithmFor example you can do\SetAlCapFnt{\large\em}to have cpation typeset in large emfont.Default is nothing so caption is typeset as the text of the document.\AlTitleFnt{<text>}is used to typeset{Algorithm:}in the caption.You can use it to have text typeset as{Algorithm:}of captions.Default is textbf.Default can be redefined by\SetAlTitleFnt{font}.6.2Restyling macros\restylealgo{style}change the layout of the algorithms as do options boxed,boxruled,ruled and algoruled.\linesnumbered makes lines of the following algorithms be auto-numbered.\linesnumberedhidden makes lines of the following algorithms be auto-numbered,but numbers stay hidden.You have to use\showln and\showlnlabel to see them.\linesnotnumbered makes lines of the following algorithms no be auto-numbered.\SetAlgoSkip{skip command}Algorithms puts extra vertical space before and after to avoid having text bumping lines of boxed or ruled algorithms.By default,this is a.You canchange this value with this macro.The four possibilities are:•\SetAlgoSkip{}]for no extra vertical skip•\SetAlgoSkip{smallskip}]to act as the default behaviour•\SetAlgoSkip{medskip}]to have a bigger skip•\SetAlgoSkip{bigskip}]to have the bigger skipNote that you can apply the skip you want by defining a macro doing it and passing itsname(without\)to\SetAlgoSkip\SetAlgoInsideSkip{skip command}Algorithms puts no extra vertical space before and after the core of the algorithm.So text is put right after the lines in boxed or ruled style.To put anextra space,use\SetAlgoInsideSkip{skip command},for example\SetAlgoInsideSkip{smallskip}, like for\SetAlgoSkip{skip command}.\AlCapSkip is the dimension of the distance between algorithm body and caption in plain and boxed mode.You can change by hands or by using\setalcapskip{0ex}.\setalcapskip{length}set the lenght of\AlCapSkip)dimension between algorithm body and caption.\setalcaphskip{length}set the horizontal skip before Algorithm:in caption when used in ruled algorithm.\dontprintsemicolon the‘;’are no more printed at the end of each line.\printsemicolon prints a‘;’at the end of each line(by default)\SetVline prints a vertical line followed by a little horizontal line between the start and the end of each block.Looks like that:\SetNoline Doesn’t print vertical lines(by default).The block is marked with keywords such as begin,end.\SetLine prints vertical lines between bloc start-end keywords as begin,end.\SetKwSty{<font>}sets the Kw typography to<font>(by default:textbf).\SetFuncSty{<font>}sets the function typography(by default:texttt).\SetArgSty{<font>}sets the argument typography(by default:emph).\SetProcNameSty{<font>}sets caption typography of procedure and function environment(by default the same as\FuncSty{)}.\SetProcArgSty{<font>}sets argument typography of procedure and function environment(by default the same as\ArgSty{)}.\SetDataSty{<font>}sets the data typography(by default:textsf).\SetCommentSty{<font>}sets the comment text typography(by default:texttt).\SetAlFnt{<font>}sets the font used by algorithm text.\SetAlCapFnt{<font>}sets the font used by caption text.\SetAlTitleFnt{<font>}sets the font used for{algorithm:}in caption or tile of algorithm (default is set to textbf).\Setnlsty{<font>}{<txt before>}{<txt after>}defines how to print line numbers: will print{<font><txt bef>thelinenumber<txt aft>}.By default\Setnlsty{textbf}{}{}.\SetTitleSty{type style}{type size}sets the typography and size of the titles defined with the macro\Titleofalgo{}(not with\caption).\nocaptionofalgo doesn’t print Algorithm and its number in the caption.This macros is ONLY active for“algoruled”or“ruled”algorithms and for the next algorithm.For example,it is useful when the algorithm just describes a function and you only want to display the name of the function in the caption.\restorecaptionofalgo restores correct captions that was corrupted by a\nocaptionofalgo macro.\restylealgo{style}sets the style of the following algorithms to that given by this macro(plain, boxed,ruled,algoruled)unlike those indicated in the options of the package(see options of the package).\SetInd{before rule space}{after rule space}sets the size of the space before the vertical rule and after.In\NoLine mode the indentation space is the sum of these two values,by default0.5em and1em\Setvlineskip{length}sets the value of the vertical space after the little horizontal line which closes a block in vlined mode.\Setnlskip{length}sets the value of the space between the line numbers and the text,by default 1em.\algomargin this is the value of the margin of all algorithms.You can change it by setting: \setlength{\algomargin}{2em}for example.The default value is the sum of the two dimensions\leftskip and\parindent when the algorithm2e package is loaded.Note that if you change this value,it will take effect with the next algorithm environment.So even if you change it inside an algorithm environment,it will not affect the current algorithm.\incmargin{length}increases the size of the\algomargin by the length given in argument.\decmargin{length}decreases the size of the\algomargin by the length given in argument.\decmargin{length}decreases the size of the\algomargin by the length given in argument.\SetSideCommentLeft equivalent to scleft option.\SetSideCommentRight equivalent to scright option.\SetFillComment equivalent tofillcomment option.\SetNoFillComment equivalent to nofillcomment option.7The predefined language keywordsHere are the english keywords predefined in the package.There are other language predefined macros provided,such as french keywords,see section9for a list of other language keywords.All these keywords are defined using macros provided by the package and described in section7.1.1.Input,output macros...•\KwData{input}•\KwResult{output}•\KwIn{input}•\KwOut{output}2.One simple common keyword:•\KwTo3.One keyword requiring an argument:•\KwRet{[value]}•\Return{[value]}4.A block:•\Begin{block inside}•\Begin(begin comment){block inside}ments:•\tcc{line(s)of comment}:comment“la”C•\tcc*{right justified side comment}:comment“la”C•\tcc*[r]{right justified side comment}:comment“la”C•\tcc*[l]{left justified side comment}:comment“la”C•\tcc*[h]{left justified comment to be put in place}:comment“la”C•\tcc*[f]{right justified comment to be put in place}:comment“la”C•\tcp{line(s)of comment}:comment“la”C++•\tcp*{right justified side comment}:comment“la”C++•\tcp*[r]{right justified side comment}:comment“la”C++•\tcp*[l]{left justified side comment}:comment“la”C++•\tcp*[h]{left justified comment to be put in place}:comment“la”C++•\tcp*[f]{right justified comment to be put in place}:comment“la”C++ 6.”if-then-else”macros:•\If{condition}{then block}•\If(then comment){condition}{then block}•\uIf{condition}{then block without end}•\uIf(then comment){condition}{then block without end}•\lIf{condition}{then’s line text}•\lIf(if comment){condition}{then’s line text}•\ElseIf{elseif block}•\ElseIf(elseif comment){elseif block}•\uElseIf{elseif block without end}•\uElseIf(elseif comment){elseif block without end}•\lElseIf{elseif’s line text}•\lElseIf(elseif comment){elseif’s line text}•\Else{else block}•\Else(else comment){else block}•\uElse{else block without end}•\uElse(else comment){else block without end}•\lElse{else’s line text}•\lElse(else comment){else’s line text}•\eIf{condition}{then block}{else block}•\eIf(then comment){condition}{then block}(else comment){else block}•\eIf(then comment){condition}{then block}{else block}•\eIf{condition}{then block}(else comment){else block}7.multiple condition selection:•\Switch(switch comment){condition}{Switch block}•\Switch{condition}{Switch block}•\Case{a case}{case block}•\Case(case comment){a case}{case block}•\uCase{a case}{case block without end}•\uCase(case comment){a case}{case block without end}•\lCase{a case}{case’s line}•\lCase(case comment){a case}{case’s line}•\Other{otherwise block}•\Other(other comment){otherwise block}•\lOther{otherwise’s line}•\lOther(other comment){otherwise’s line}8.loops with”end condition”test at the beginning:•\For{condition}{text loop}•\For(for comment){condition}{text loop}•\lFor{condition}{line text loop}•\lFor(for comment){condition}{line text loop}•\While{condition}{text loop}•\While(while comment){condition}{text loop}•\lWhile{condition}{line text loop}•\lWhile(while comment){condition}{line text loop}•\ForEach{condition}{text loop}•\ForEach(foreach comment){condition}{text loop}•\lForEach{condition}{line text loop}•\lForEach(foreach comment){condition}{line text loop}•\ForAll{condition}{text loop}•\ForAll(forall comment){condition}{text loop}•\lForAll{condition}{line text loop}•\lForAll(forall comment){condition}{line text loop}9.loops with”end condition”test at the end:•\Repeat{end condition}{text loop}•\Repeat(repeat comment){end condition}{text loop}(until comment)•\Repeat(repeat comment){end condition}{text loop}•\Repeat{end condition}{text loop}(until comment)•\lRepeat{end condition}{line text loop}•\lRepeat(repeat comment){end condition}{line text loop}Here we describe how they are obtained:1.\SetKwInput{KwData}{Data}\SetKwInput{KwResult}{Result}\SetKwInput{KwIn}{Input}\SetKwInput{KwOut}{Output}2.\SetKw{KwTo}{to}3.\SetKw{KwRet}{return}\SetKw{Return}{return}4.\SetKwBlock{Begin}{begin}{end}5.\SetKwComment{tcc}{/*}{*/}\SetKwComment{tcp}{//}{}6.\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}7.\SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{endsw}8.\SetKwFor{For}{for}{do}{endfor}\SetKwFor{While}{while}{do}{endw}\SetKwFor{ForEach}{foreach}{do}{endfch}\SetKwAll{ForEach}{forall}{do}{endfall}9.\SetKwRepeat{Repeat}{repeat}{until}7.1To define your own language keywordsNote that all these macros verify if the keywords are already defined and do a renewcommand if they are.So you can overload the default definitions of this package with your own.\SetKw{Kw}{thetext}defines the macro\Kw which defines a keyword thetext and prints it in keyword typography.It can take one argument:backslash Kw{arg}.If so,arg is printed in argument typography.\SetKwData{Kw}{thetext}defines the macro\Kw{w}hich defines a data text.Prints thetext in data typography.Note that this macros can takes one argument as function macros.\SetKwInput{Kw}{input}defines the macro\Kw{arg}which prints input followed by‘:’in key word typography,and behind the argument arg.Typically used to define macros such as \Input{data}or\Output{result}.Note that arg will be shifted so that all the text is vertically aligned and to the right of the‘:’.\SetKwInOut{Kw}{input}works as\SetKwInput{Kw}{input}.But the position of the‘:’isfixed and set by the longest keyword defined by this macro.\ResetInOut{input}resets the position of the‘:’for all macros defined previously by \SetKwInOut{Kw}{input}.The new position isfixed depending on the size of the text input given in argument.\SetKwInParam{Kw}{text1}{text2}defines the macro\Kw{name}{arg}which prints name fol-lowed by text1in key word typography,behind the argument arg,followed by text2in key word typography.Typically used when the algorithm described a function in order to define a macro which allows to give the name of the function and to show its arguments.Note that arg will be shifted so that all the text is vertically aligned and to the right of text1.Example\SetKwInParam{Func}{(}{)}defines macro\Func and\Func{function}{arg1,arg2, arg3}gives function(arg1,arg2,arg3).\SetKwFunction{KwFn}{Fn}defines a macro\KwFn{arg}which prints Fn in Function typography and its argument arg in argument typography,surrounded by a pair of parentheses.\SetKwFunction{Dothat}{Do that}defines the macro\DoThat{this},which is equivalent to\FuncSty{Do that(}\ArgSty{this}\FuncSty{)}which gives:Do that(this).Note that you can also use it without arguments,it will be printed without‘()’,example: \SetKwFunction{Fn}{TheFunction}use as\Fn gives TheFunction.Keywords(with or without arguments)and functions defined previously in normal text(not in an algorithm environment)can be used outside an algorithm environment.You can use it by typing\DoThat{toto}(for a function defined by\SetKwFunction{Dothat}{Do that}), you will obtain Do That(toto).\SetKwBlock{Begin}{begin}{end}defines a macro\Begin{txt}which denotes a block.The text is surrounded by the words begin and end in keyword typography and shifted to the right(indented).In\Vline or\Line mode a straight vertical line is added.\Begin(side text){text}gives also text in a block surrounded by begin and end,but side text if put after the begin bined with\tcc*[f]macro,it allows you to put comments on the same line as begin.\SetKwComment{Comment}{start}{end}defines a macr\Comment{text comment}which writes text comment between start and end.Note that start or end can be empty.It defines also\Comment*{side comment text}macro which allows to put comment on the same line as the code.This macro can take various option to control its behaviour:\Comment*[r]{side comment text}put the end of line mark(’;’by default)and side com-ment text just after and right justified,then end the line.It is the default.\Comment*[l]{side comment text}same thing but side comment text is left justified.\Comment*[h]{side comment text}put side comment right after the text.No end of line mark is put,and line is not terminated(is up to you to put\;to end the line).\Comment*[f]{side comment text}same as the previous one but with side comment text right justified.\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}defines several macros to give the opportunity to write all if-then-else-elseif-endif possibilities:•\If{cond}{Then’s text}Then’s text is writen in a block(below then and on several lines)and terminating bythe endif given in the last argument.•\ElseIf{ElseIf’s text}ElseIf’s text is writen in a block and terminating by the endif.•\Else{Else’s text}Else’s text is writen in a block and terminating by the endif.•\lIf{cond}{Then’s text}Then’s text is written on the same line as then.No endif is printed.•\lElseIf{ElseIf’s text}ElseIf’s text is written on the same line as else if.No endif is printed.•\lElse{Else’s text}Else’s text is written on the same line as else.No endif is printed.•\uIf{cond}{Then’s text}(for uncomplete if)defines a If block unterminated like in a\eIf block,i.e.don’t print the endif or don’tput the little horizontal line in Vline mode(see examples below).•\uElseIf{ElseIf’s text}(for uncomplete elseif)Same explanation as for\uIf but with else if.•\uElse{Else’s text}(for uncomplete else)Same explanation as for\uElseIf but with else.•\eIf{cond}{Then’s text}{Else’s text}equivalent to the use of\uIf followed by\Else.The macros which begin with a‘l’(l as line)denote that the text passed in argument will be printed on the same line while with the others the text is printed in a block and shifted.You should put\;at the end of“l macros”.The macros which begin with a‘u’(u as uncomplete)denote that the text passed in argu-ment will be printed in a block not terminated by endif.They are useful to chain different alternatives.The keywords then and else are automatically printed.cond is always printed in argument typography just behind the keyword if.All this macros can be combined with()and\Comment*macros to put comments after main keywords as If,Else or ElseIf(see list of predefined keywords above and example below).Some examples with\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif} the default definition given in the package:\SetVline\eIf{cond1}{a line\;a line\;}{another line\; another line\; }=⇒if cond1thena line;a line;elseanother line;another line;。
latex中输入算法排版可能需要的包:\usepackage{algorithm} //format of the algorithm \usepackage{algorithmic} //format of the algorithm \usepackage{multirow} //multirow for format of table\usepackage{amsmath}\usepackage{xcolor}\DeclareMathOperator*{\argmin}{argmin} //argmin或argmax公式的排版\renewcommand{\algorithmicrequire}{\textbf{Input:}} //Us e Input in the format of Algorithm\renewcommand{\algorithmicensure}{\textbf{Output:}} //Us eOutput in the format of Algorithm排版图片可能需要的包:\usepackage{graphics}\usepackage{graphicx}\usepackage{epsfig}算法的排版举例:\begin{algorithm}[htb] %算法的开始\caption{ Framework of ensemble learning for our system.} %算法的标题\label{alg:Framwork} %给算法一个标签,这样方便在文中对算法的引用\begin{algorithmic}[1] %不知[1]是干嘛的?\REQUIRE ~~\\ %算法的输入参数:InputThe set of positive samples for current batch, $P_n$;\\The set of unlabelled samples for current batch, $U_n$;\\Ensemble of classifiers on former batches, $E_{n-1}$;\ENSURE ~~\\ %算法的输出:OutputEnsemble of classifiers on the current batch, $E_n$;\STATE Extracting the set of reliable negative and/or positive samples $T_n$ from $U_n$ with help of $P_n$; \label{code:fram:extract} %算法的一个陈述,对应算法的一个步骤或公式之类的; \label{ code:fram:extract }对此行的标记,方便在文中引用算法的某个步骤\STATE Training ensemble of classifiers $E$ on $T_n \cup P_n$, with help of data in former batches; \label{code:fram:trainbase}\STATE $E_n=E_{n-1}\cup E$; \label{code:fram:add}\STATE Classifying samples in $U_n-T_n$ by $E_n$; \label{code:fram:classify}\STATE Deleting some weak classifiers in $E_n$ so as to keep the capacity of $E_n$; \label{code:fram:select}\RETURN $E_n$; %算法的返回值\end{algorithmic}\end{algorithm}排版效果图:在文中对算法和算法的某个步骤的引用:Therefore, in step \ref{code:fram:extract} of algorithm \ref{alg:Framwork}, we extract $T_n$, a set of reliable negative samples1、 For和While循环语句的排版举例(1)排版效果图(2)排版代码\begin{algorithm}[h]\caption{An example for format For \& While Loop inAlgorithm}\begin{algorithmic}[1]\FOR{each $i\in [1,9]$}\STATE initialize a tree $T_{i}$ with only a leaf (the root);\\ \STATE $T=T\bigcup T_{i};$\\\ENDFOR\FORALL {$c$ s h that $c\in RecentMBatch(E_{n-1})$} \label{code:TrainBase:getc}\STATE $T=T \cup PosSample(c)$; \label{code:TrainBase:pos}\ENDFOR;\FOR{$i=1$; $i<n$; $i++$ }\STATE $//$ Your source here;\ENDFOR\FOR{$i=1$ to $n$}\STATE $//$ Your source here;\ENDFOR\STATE $//$ Reusing recent base classifiers. \label{code:recentStart}\WHILE {$(|E_n| \leq L_1 )and( D \neq \phi)$}\STATE Selecting the most recent classifier $c_i$ from $D$;\STATE $D=D-c_i$;\STATE $E_n=E_n+c_i$;\ENDWHILE \label{code:recentEnd}\end{algorithmic}\end{algorithm} 转自:。
Latex使⽤:在latex中添加算法模块在Miktex下有三个latex algorithm包,分别为:algorithm,algorithmic,algorithm2e三个,其中algorithm,algorithmic经常成套使⽤:latex中algorithm模板为:latex⽂件中顶端加⼊的package:\usepackage{algorithm}\usepackage{algorithmic}\usepackage{setspace}算法块代码:\begin{algorithm}[htb]\setstretch{1.35} %设置具有指定弹⼒的橡⽪长度(原⾏宽的1.35倍)\caption{}\label{alg:Framwork}\begin{algorithmic}\REQUIRE ~~\\The set of positive samples for current batch, $P_n$;\\The set of unlabelled samples for current batch, $U_n$;\\Ensemble of classifiers on former batches, $E_{n-1}$;\ENSURE ~~\\Ensemble of classifiers on the current batch, $E_n$;Extracting the set of reliable negative and/or positive samples $T_n$ from $U_n$ with help of $P_n$;\\\label{ code:fram:extract }Training ensemble of classifiers $E$ on $T_n \cup P_n$, with help of data in former batches;\\\label{code:fram:trainbase}$E_n=E_{n-1}\cup E$;\\\label{code:fram:add}Classifying samples in $U_n-T_n$ by $E_n$;\\\label{code:fram:classify}Deleting some weak classifiers in $E_n$ so as to keep the capacity of $E_n$;\\\label{code:fram:select}$E_n$;\\\end{algorithmic}\end{algorithm}实际算法结果图⽰为:第⼆种⽤法:使⽤algorithm2e包进⾏处理\documentclass{article}\usepackage{algorithm2e,setspace}\begin{document}\begin{algorithm}\setstretch{1.35}\SetAlgoLined\KwData{this text}\KwResult{how to write algorithm with \LaTeX2e }initialization\;\While{not at end of this document}{read current\;\eIf{understand}{go to next section\;current section becomes this one\;}{go back to the beginning of current section\;}}\caption{How to write algorithms}\end{algorithm}\bigskip\begin{algorithm}\SetAlgoLined\KwData{this text}\KwResult{how to write algorithm with \LaTeX2e }initialization\;\While{not at end of this document}{read current\;\eIf{understand}{go to next section\;current section becomes this one\;}{go back to the beginning of current section\;}}\caption{How to write algorithms}\end{algorithm}\end{document}上述代码分别对应两个算法,所获得的算法块分别为:Latex中的常⽤算法块如上所述,使⽤过程中其它技巧可查询之后进⾏设置。
latex公式编辑器使用技巧下载温馨提示:该文档是我店铺精心编制而成,希望大家下载以后,能够帮助大家解决实际的问题。
文档下载后可定制随意修改,请根据实际需要进行相应的调整和使用,谢谢!并且,本店铺为大家提供各种各样类型的实用资料,如教育随笔、日记赏析、句子摘抄、古诗大全、经典美文、话题作文、工作总结、词语解析、文案摘录、其他资料等等,如想了解不同资料格式和写法,敬请关注!Download tips: This document is carefully compiled by the editor. I hope that after you download them, they can help you solve practical problems. The document can be customized and modified after downloading, please adjust and use it according to actual needs, thank you!In addition, our shop provides you with various types of practical materials, such as educational essays, diary appreciation, sentence excerpts, ancient poems, classic articles, topic composition, work summary, word parsing, copy excerpts, other materials and so on, want to know different data formats and writing methods, please pay attention!在现代科技环境下,文档编辑与排版已经成为我们日常工作中必不可少的一部分。
latex数学公式使用教程要使用LaTeX编写数学公式,您需要掌握一些基本的语法和命令。
下面是一个简单的教程,帮助您入门。
1. 引入amsmath宏包:在您的LaTeX文档的导言区,添加如下代码:```\usepackage{amsmath}```这个宏包提供了一些常用的数学命令和环境。
2. 行内公式:如果您想在文字中插入一个简短的数学公式,可以使用$符号将公式括起来。
例如,$y = mx + b$会产生一个行内公式。
3. 居中公式:如果您想将一个较长的数学公式居中显示,可以使用\[\]环境。
例如,```\[\sum_{i=1}^{n} i = \frac{n(n+1)}{2}\]```会产生一个居中显示的求和公式。
4. 基本数学符号:您可以使用各种数学符号,例如+、-、*、/等。
您还可以使用^和_来表示上标和下标。
例如,x^2表示x的平方,a_i表示a的第i个分量。
5. 分数:要表示一个分数,可以使用\frac命令。
例如,\frac{1}{2}表示1/2这个分数。
6. 根号和指数:要表示一个根号,可以使用\sqrt命令。
例如,\sqrt{2}表示根号2。
要表示一个指数,可以使用^符号。
例如,x^2表示x的平方。
7. 求和和积分:要表示一个求和符号,可以使用\sum命令,后跟上下限。
例如,\sum_{i=1}^{n} i表示求和公式。
要表示一个积分符号,可以使用\int命令,后跟上下限。
例如,\int_{0}^{1} x^2 dx表示积分公式。
8. 矩阵和方程组:要表示一个矩阵,可以使用\begin{matrix}...\end{matrix}环境。
例如,```\[\begin{matrix}1 &2 \\3 &4 \\\end{matrix}\]```表示一个2x2的矩阵。
要表示一个方程组,可以使用\begin{cases}...\end{cases}环境。
例如,```\[\begin{cases}x + y = 1 \\2x - y = 3 \\\end{cases}\]```表示一个包含两个方程的方程组。
latex算法常用语法在LaTeX中,编写算法通常使用algorithm2e宏包或者algorithmicx宏包。
以下是一些常用的语法和示例:使用algorithm2e宏包的示例:latex.\usepackage[ruled,vlined]{algorithm2e}。
\begin{algorithm}。
\SetAlgoLined.\KwResult{Write here the result }。
initialization\;\While{While condition}{。
instructions\;\eIf{condition}{。
instructions1\;instructions2\;}{。
instructions3\;}。
}。
\caption{How to write algorithms}。
\end{algorithm}。
使用algorithmicx宏包的示例:latex.\usepackage{algorithm}。
\usepackage{algpseudocode}。
\begin{algorithm}。
\caption{Euclid’s algorithm}。
\begin{algorithmic}[1]\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}。
\State $r\gets a\bmod b$。
\While{$r\not=0$}\Comment{We have the answer if r is 0}。
\State $a\gets b$。
\State $b\gets r$。
\State $r\gets a\bmod b$。
\EndWhile\label{euclidendwhile}。
\State \textbf{return} $b$\Comment{The gcd is b}。
\EndProcedure.\end{algorithmic}。
markdown中latex写算法描述以markdown中latex写算法描述为标题,本文将介绍如何使用LaTeX编写算法描述。
LaTeX是一种功能强大的排版系统,广泛应用于学术界和科研领域。
通过LaTeX的算法描述语法,我们可以清晰、准确地展示算法的步骤和逻辑。
为了编写算法描述,我们需要使用LaTeX中的algorithm2e宏包。
该宏包提供了丰富的命令和环境,用于描述算法的输入、输出、流程和控制结构。
下面是一段使用algorithm2e宏包编写的算法描述示例:```latex\begin{algorithm}[H]\SetAlgoLined\KwIn{输入参数1, 输入参数2}\KwOut{输出参数}\While{循环条件}{执行循环操作\;\If{条件}{执行条件操作\;}\ElseIf{另一条件}{执行另一条件操作\;}\Else{执行其他操作\;}}\Return 输出参数\;\caption{算法描述示例}\end{algorithm}```在上面的示例中,我们首先使用`\begin{algorithm}[H]`和`\SetAlgoLined`命令设置算法环境,并使用`\KwIn`和`\KwOut`命令分别描述算法的输入和输出参数。
接着使用`\While`命令定义一个循环,并在循环体中使用`\If`、`\ElseIf`和`\Else`命令定义条件分支。
最后使用`\Return`命令返回输出参数,并使用`\caption`命令为算法添加标题。
除了基本的输入、输出和控制结构,algorithm2e宏包还提供了一些其他功能,例如循环的退出条件、循环体的缩进、注释和引用等。
通过合理使用这些功能,我们可以编写出规范、清晰的算法描述。
在实际使用中,我们可以将上述LaTeX代码嵌入到markdown文档中,并使用合适的标题和段落格式进行排版。
这样,我们既可以享受markdown的简洁和易用性,又可以利用LaTeX的强大排版功能展示算法描述。
LaTex 语法汇总(不定期更新)⽬录字体希腊字母粗体希腊字母语法:\boldsymbol{\alpha \beta \gamma \Alpha \Beta \Gamma}效果:\boldsymbol{\alpha \beta \gamma \Alpha \Beta \Gamma}⿊板粗体语法:\mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZ}效果:\mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZ}⿊板粗体()⼀般⽤于表⽰数学和物理学中的向量或集合的符号。
上下标、分数和括号类型语法效果⼤写字母\Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta\Theta\Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta\Theta⼤写字母\Iota \Kappa \Lambda \Mu \Nu \Xi \Omicron \Pi \Iota \Kappa \Lambda \Mu \Nu \Xi \Omicron \Pi ⼤写字母\Rho \Sigma \Tau \Upsilon \Phi \Chi \Psi\Omega \Rho \Sigma \Tau \Upsilon \Phi \Chi \Psi\Omega ⼩写字母\alpha \beta \gamma \delta \epsilon \zeta \eta\theta \alpha \beta \gamma \delta \epsilon \zeta \eta\theta ⼩写字母\iota \kappa\varkappa \lambda \mu \nu \xi \omicron\pi\iota \kappa\varkappa \lambda \mu \nu \xi \omicron\pi⼩写字母\rho \sigma \tau \upsilon \phi \chi \psi\omega\rho \sigma \tau \upsilon \phi \chi \psi\omega异体字母\Epsilon\epsilon\varepsilon \Epsilon\epsilon\varepsilon 异体字母\Theta\theta\vartheta \Theta\theta\vartheta 异体字母\Kappa\kappa\varkappa\Kappa\kappa\varkappa异体字母\Pi\pi\varpi \Pi\pi\varpi 异体字母\Rho\rho\varrho \Rho\rho\varrho 异体字母\Sigma\sigma\varsigma\Sigma\sigma\varsigma异体字母\Phi\phi\varphi\Phi\phi\varphi功能语法效果功能语法效果分数\frac{2}{4}=0.5\frac{2}{4}=0.5⼩型分数\tfrac{2}{4} = 0.5\tfrac{2}{4} = 0.5⼤型分数(嵌套)\cfrac{2}{c + \cfrac{2}{d +\cfrac{2}{4}}} =a\cfrac{2}{c + \cfrac{2}{d +\cfrac{2}{4}}} =a上标a^2a^2下标a_2a_2上下标x_2^3x_2^3组合a_{i,j}a_{i,j}前置上下标{}_12!X_34{}_1^2\!X_3^4上弧\overset{\frown}{AB}\overset{\frown}{AB}上划线\overline{h i j}\overline{h i j}下划线\underline{k l m}\underline{k l m}\vec{c}\vec{c}\widehat{e f g}\widehat{e f g}\overleftarrow{a b}\overleftarrow{a b}\overrightarrow{cd}\overrightarrow{cd}Processing math: 0%可以使⽤ \big, \Big, \bigg, \Bigg 控制括号的⼤⼩,⽐如代码: \Bigg ( \bigg [ \Big \{\big\langle \left | \| x \| \right | \big \rangle\Big\}\bigg ] \Bigg )效果:\Bigg ( \bigg [ \Big \{\big\langle \left | \| x \| \right | \big \rangle\Big\}\bigg ] \Bigg )单竖线,绝对值语法: \left\|\frac{a}{b}\right\|效果:\left|\frac{a}{b}\right|双竖线语法:| \left\| \frac{a}{b} \right\|效果:\left\| \frac{a}{b}\right\|在字符头上添加符号常⽤函数和符号d}d}圆括号,⼩括号\left( \frac{a}{b} \right)\left( \frac{a}{b} \right)⽅括号,中括号\left[ \frac{a}{b}\right]\left[ \frac{a}{b}\right]花括号,⼤括号\left{ \frac{a}{b} \right}\left\{ \frac{a}{b} \right\}⾓括号\left \langle\frac{a}{b} \right\rangle\left \langle\frac{a}{b} \right\rangle上取整\left \lceil \frac{c}{d} \right\rceil\left \lceil \frac{c}{d} \right\rceil下取整\left \lfloor\frac{a}{b} \right\rfloor\left \lfloor \frac{a}{b} \right \rfloor混合括号1\left [ 0,1 \right )\left [ 0,1 \right )混合括号2\left \langle \psi\right)\left \langle \psi\right)单左括号\left { \frac{a}{b} \right .\left \{ \frac{a}{b} \right .单右括号\left . \frac{a}{b}\right }\left . \frac{a}{b}\right \}上括号1\overbrace{1+2+\cdots+100}\overbrace{1+2+\cdots+100}上括号2\begin{matrix}5050 \\overbrace{1+2+\cdots+100}\end{matrix}\begin{matrix}5050 \\\overbrace{1+2+\cdots+100}\end{matrix}下括号1\underbrace{a+b+\cdots+z}\underbrace{a+b+\cdots+z}下括号2\begin{matrix}\underbrace{a+b+\cdots+z } \26\end{matrix}\begin{matrix}\underbrace{a+b+\cdots+z } \\26\end{matrix}⼆项式系数\dbinom{n}{r}=\binom{n}{n-r}=C n_r=C n_{n-r}\dbinom{n}{r}=\binom{n}{n-r}=C^n_r=C^n_{n-r}⼩型⼆项式系数\tbinom{n}{r}=\tbinom{n}{n-r}=C n_r=C n_{n-r}\tbinom{n}{r}=\tbinom{n}{n-r}=C^n_r=C^n_{n-r}⼤型⼆项式系数\binom{n}{r}=\dbinom{n}{n-r}=C n_r=C n_{n-r}\binom{n}{r}=\dbinom{n}{n-r}=C^n_r=C^n_{n-r}$$说明语法效果加^号\hat{x}\hat{x}加横线\overline{x}\overline{x}加宽^\widehat{x}\widehat{x}加波浪线\widetilde{x}\widetilde{x}加⼀个点\dot{x}\dot{x}加两个点\ddot{x}\ddot{x}语法效果语法效果语法效果\sin\theta\sin\theta\cos\beta\cos\beta\tan\gamma\tan\gamma \arcsin\delta\arcsin\delta\max H\max H\min L\min L \sinh g\sinh g\ln X\ln X\log_\alpha X\log_\alpha X \exp b\exp b\sqrt[3]{N}\sqrt[3]{N}\sqrt{N}\sqrt{N} \surd{N}\surd{N}\circ (空⼼圆)\circ\times (乘号)\times微积分符号集合和逻辑符号关系符号箭头功能语法效果效果语法效果导数点\dot{x} \ddot{y}\dot{x} \ddot{y}导数x^\prime x^\prime 微分1\nabla \nabla 微分2\partial x\partial x微分3\mathrm{d}x \mathrm{d}x 求和1\sum_{k=1}^Nk^2\sum_{k=1}^Nk^2求和2\begin{matrix}\sum_{k=1}^N k^2\end{matrix}\begin{matrix} \sum_{k=1}^Nk^2 \end{matrix}求积1\prod_{i=1}^Nx_i \prod_{i=1}^N x_i \begin{matrix} \prod_{i=1}^Nx_i \end{matrix}\begin{matrix} \prod_{i=1}^Nx_i \end{matrix}上积1\coprod_{i=1}^Nx_i \coprod_{i=1}^Nx_i 上积2\begin{matrix}\coprod_{i=1}^N x_i\end{matrix}\begin{matrix}\coprod_{i=1}^N x_i\end{matrix}极限1\lim_{n \to \infty}x_n \lim_{n \to \infty}x_n 极限2\begin{matrix} \lim_{n \to \infty}x_n\end{matrix}\begin{matrix} \lim_{n \to \infty}x_n\end{matrix}积分1\int_{-N}^{N}e^x, dx \int_{-N}^{N}e^x\, dx 积分2\begin{matrix} \int_{-N}^{N}e^x, dx\end{matrix}\begin{matrix} \int_{-N}^{N}e^x\, dx\end{matrix}双重积分\iint_{D}^{W} ,dx,dy \iint_{D}^{W} \,dx\,dy 三重积分\iiint_{E}^{V} , dx,dy,dz \iiint_{E}^{V} \, dx\,dy\,dz 四重积分\iiiint_{F}^{U} ,dx,dy,dz,dt\iiiint_{F}^{U} \,dx\,dy\,dz\,dt闭合积分\oint_{C} x^3, dx + 4y^2, dy\oint_{C} x^3\, dx + 4y^2\, dy语法效果语法效果语法效果\forall \forall \exists \exists \varnothing \varnothing \empty \empty \emptyset\emptyset\subset \subset \in \in \ni \ni \not\in 或\notin \not\in \subseteq \subseteq \supset \supset \supseteq \supseteq \cap \cap \bigcap \bigcap \sqsubset \sqsubset \cup \cup \bigcup \bigcup \biguplus \biguplus \sqsubseteq \sqsubseteq \sqsupset \sqsupset \sqsupseteq \sqsupseteq \sqcap \sqcap \sqcup \sqcup \bigsqcup \bigsqcup p p \land \land \bigwedge \bigwedge \bar{q} \to p\bar{q} \to p\lor \lor \bigvee \bigvee \lnot\lnot\neg q\neg q\setminus\setminus语法效果语法效果语法效果\leftarrow \leftarrow \gets \gets \longleftarrow \longleftarrow \rightarrow \rightarrow \to \to \longrightarrow \longrightarrow \leftrightarrow \leftrightarrow \mapsto \mapsto \longmapsto \longmapsto \searrow \searrow \swarrow \swarrow \uparrow \uparrow \nearrow\nearrow\nwarrow\nwarrow\downarrow\downarrow\rightharpoonup\rightharpoonup\leftharpoonup\leftharpoonup\updownarrow\updownarrow \rightharpoondown\rightharpoondown\leftharpoondown\leftharpoondown\Leftrightarrow\Leftrightarrow \upharpoonleft\upharpoonleft\upharpoonright\upharpoonright\Updownarrow\Updownarrow \downharpoonleft\downharpoonleft\downharpoonright\downharpoonright\Uparrow\Uparrow \Leftarrow\Leftarrow\Rightarrow\Rightarrow\Downarrow\Downarrow波浪线⼀般⽂字环境: \textasciitilde,效果:\textasciitilde公式环境: \sim ,效果: \sim矩阵和⾏列式语法: \begin{matrix} x & y \\ z & v \end{matrix}效果:\begin{matrix} x & y \\ z & v \end{matrix}语法: \begin{vmatrix} x & y \\ z & v \end{vmatrix}效果:\begin{vmatrix} x & y \\ z & v \end{vmatrix}语法: \begin{Vmatrix} x & y \\ z & v \end{Vmatrix}效果:\begin{Vmatrix} x & y \\ z & v \end{Vmatrix}语法: \begin{Bmatrix} x & y \\ z & v \end{Bmatrix}效果:\begin{Bmatrix} x & y \\ z & v \end{Bmatrix}语法: \begin{pmatrix} x & y \\ z & v \end{pmatrix}效果:\begin{pmatrix} x & y \\ z & v \end{pmatrix}语法: \bigl( \begin{smallmatrix} a&b\\ c&d \end{smallmatrix} \bigr)效果:\bigl( \begin{smallmatrix} a&b\\ c&d \end{smallmatrix} \bigr)语法: \begin{bmatrix} 0 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 0 & \cdots & 0 \end{bmatrix}效果:\begin{bmatrix} 0 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 0 & \cdots & 0 \end{bmatrix}语法: \begin{array}{\|c\|c\|\|c\|} a & b & S \\ \hline 0&0&1\\ 0&1&1\\ 1&0&1\\ 1&1&0\\ \end{array}效果:\begin{array}{\|c\|c\|\|c\|} a & b & S \\ \hline 0&0&1\\ 0&1&1\\ 1&0&1\\ 1&1&0\\ \end{array}等式和⽅程式条件定义公式:f(n) = \begin{cases} n/2, & \mbox{if }n\mbox{ is even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{cases}效果:f(n) = \begin{cases} n/2, & \mbox{if }n\mbox{ is even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{cases}⽅程组公式:\begin{cases} 3x + 5y + z \\ 7x - 2y + 4z \\ -6x + 3y + 2z \end{cases}效果:\begin{cases} 3x + 5y + z \\ 7x - 2y + 4z \\ -6x + 3y + 2z \end{cases}多⾏等式公式:\begin{align} f(x) & = (m+n)^2 \\ & = m^2+2mn+n^2 \\ \end{align}效果:\begin{align} f(x) & = (m+n)^2 \\ & = m^2+2mn+n^2 \\ \end{align}多⾏等式公式:\begin{alignat}{2} f(x) & = (m-n)^2 \\ f(x) & = (-m+n)^2 \\ & = m^2-2mn+n^2 \\ \end{alignat}效果:\begin{alignat}{2} f(x) & = (m-n)^2 \\ f(x) & = (-m+n)^2 \\ & = m^2-2mn+n^2 \\ \end{alignat}多⾏等式(左对齐)公式:\begin{array}{lcl} z & = & a \\ f(x,y,z) & = & x + y + z \end{array}效果:\begin{array}{lcl} z & = & a \\ f(x,y,z) & = & x + y + z \end{array}多⾏等式(右对齐)公式:\begin{array}{lcr} z & = & a \\ f(x,y,z) & = & x + y + z \end{array}效果:\begin{array}{lcr} z & = & a \\ f(x,y,z) & = & x + y + z \end{array}空格功能语法效果宽度2个quad空格\alpha\qquad\beta\alpha\qquad\beta2mquad空格\alpha\quad\beta\alpha\quad\beta m⼤空格\alpha\ \beta\alpha\ \beta\frac{m}{3}中等空格\alpha\;\beta\alpha\;\beta\frac{2m}{7}⼩空格\alpha\,\beta\alpha\,\beta\frac{m}{6}没有空格\alpha\beta\alpha\beta0紧贴\alpha\!\beta\alpha\!\beta-\frac{m}{6}⽬录。
latex algorithm 语法LaTeX是一种流行的排版工具,可以用来创建各种类型的文档,包括算法和程序。
LaTeX Algorithm 语法是一种用于编写算法和程序的语法,它提供了一些特殊的命令和环境,用于排版和格式化代码。
下面是一些常用的 LaTeX Algorithm 语法:1. 环境LaTeX Algorithm 环境用于排版算法。
它的基本语法如下:begin{algorithm}caption{算法名称}label{alg:identifier}begin{algorithmic}[1]REQUIRE 输入ENSURE 输出STATE 状态IF{条件}STATE 状态1ELSESTATE 状态2ENDIFWHILE{条件}STATE 循环体ENDWHILEend{algorithmic}end{algorithm}其中,caption 用于指定算法名称,label 用于为算法添加标签以便后续引用,REQUIRE 和 ENSURE 用于指定输入和输出,STATE 用于指定状态,IF 和 ELSE 用于条件判断,WHILE 和 ENDWHILE 用于循环。
2. 命令LaTeX Algorithm 还提供了一些命令来帮助排版和格式化代码,例如:STATE 用于指定代码状态并显示行号。
IF 和 ELSE 用于条件判断。
FOR 和 ENDFOR 用于循环。
RETURN 用于返回值。
REPEAT 和 UNTIL 用于重复执行代码块。
3. 样式LaTeX Algorithm 还提供了一些样式来帮助排版和格式化代码,例如:algorithmicindent 用于指定缩进量。
algorithmicrequire 和 algorithmicensure 用于指定输入和输出。
algorithmiccomment 用于添加注释。
STATE、IF、FOR、RETURN、REPEAT 等命令还可以通过添加前缀和后缀来改变其样式。
algorithm排版可能需要的套件\documentclass[journal]{IEEEtran}\usepackage{algorithm}%\usepackage{algorithmic}\usepackage{algpseudocode}\usepackage{amsmath}\usepackage{graphics}\usepackage{epsfig}其中algorithmic在compile時會出現! LaTex Error: Command \algorithm already defined.Or name \end... illegal, see p.192 of the manual原因不是很清楚,所以只好先mark掉\renewcommand{\algorithmicrequire}{\textbf{Input:}} % Use Input in the format of Algorithm\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm 網路上範例一:\begin{algorithm}[htb]\caption{ Framework of ensemble learning for our system.}\label{alg:Framwork}\begin{algorithmic}[1]\RequireThe set of positive samples for current batch, $P_n$;The set of unlabelled samples for current batch, $U_n$;Ensemble of classifiers on former batches, $E_{n-1}$;\EnsureEnsemble of classifiers on the current batch, $E_n$;\State Extracting the set of reliable negative and/or positive samples $T_n$ from $U_n$ with help of $P_n$;\label{code:fram:extract}\State Training ensemble of classifiers $E$ on $T_n \cup P_n$, with help of data in former batches;\label{code:fram:trainbase}\State $E_n=E_{n-1}cup E$;\label{code:fram:add}\State Classifying samples in $U_n-T_n$ by $E_n$;\label{code:fram:classify}\State Deleting some weak classifiers in $E_n$ so as to keep the capacity of $E_n$;\label{code:fram:select} \\\Return $E_n$;\end{algorithmic}\end{algorithm}排版效果圖:網路上範例二:\begin{algorithm}[h]\caption{An example for format For \& While Loop in Algorithm} \begin{algorithmic}[1]\For{each $i\in [1,9]$}\State initialize a tree $T_{i}$ with only a leaf (the root);\State $T=T\cup T_{i};$\EndFor\ForAll {$c$ such that $c\in RecentMBatch(E_{n-1})$}\label{code:TrainBase:getc}\State $T=T\cup PosSample(c)$;\label{code:TrainBase:pos}\EndFor;\For{$i=1$; $i<n$; $i++$ }\State $//$ Your source here;\EndFor\For{$i=1$ to $n$}\State $//$ Your source here;\EndFor\State $//$ Reusing recent base classifiers.\label{code:recentStart}\While {$(|E_n| \leq L_1 )and( D \neq \phi)$}\State Selecting the most recent classifier $c_i$ from $D$;\State $D=D-c_i$;\State $E_n=E_n+c_i$;\EndWhile\label{code:recentEnd}\end{algorithmic}\end{algorithm}排版效果圖:個人範例:\begin{algorithm}[h]\caption{Conjugate Gradient Algorithm with Dynamic Step-Size Control}\label{alg::conjugateGradient}\begin{algorithmic}[1]\Require$f(x)$: objective funtion;$x_0$: initial solution;$s$: step size;\Ensureoptimal $x^{*}$\State initial $g_0=0$ and $d_0=0$;\Repeat\State compute gradient directions $g_k=\bigtriangledown f(x_k)$;\State compute Polak-Ribiere parameter $\beta_k=\frac{g_k^{T}(g_k-g_{k-1})}{\parallel g_{k-1} \parallel^{2}}$;\State compute the conjugate directions $d_k=-g_k+\beta_k d_{k-1}$;\State compute the step size $\alpha_k=s/\parallel d_k \parallel_{2}$;\Until{($f(x_k)>f(x_{k-1})$)}\end{algorithmic}\end{algorithm}排版效果圖:先前所使用的套件為algorithm或algorithmic接下來介紹另一個寫algorithm的套件alogrithm2e首先使用\usepackage指令\usepackage[linesnumbered,boxed]{algorithm2e}接下來是網路範例:\begin{algorithm}\caption{identifyRowContext}\KwIn{$r_i$, $Backgrd(T_i)$=${T_1,T_2,\ldots ,T_n}$ and similarity threshold $\theta_r$}\KwOut{$con(r_i)$}$con(r_i)= \Phi$\;\For{$j=1;j \le n;j \ne i$}{float $maxSim=0$\;$r^{maxSim}=null$\;\While{not end of $T_j$}{compute Jaro($r_i,r_m$)($r_m\in T_j$)\;\If{$(Jaro(r_i,r_m) \ge \theta_r)\wedge (Jaro(r_i,r_m)\ge r^{maxSim})$}{replace $r^{maxSim}$ with $r_m$\;}}$con(r_i)=con(r_i)\cup {r^{maxSim}}$\;}return $con(r_i)$\;\end{algorithm}排版效果圖:延伸幾個問題:一、如何修改Algorithm的標題為中文的"演算法”?在\begin{document}之前加入\renewcommand{\algorithmcfname}{算法} 即可(註:需先安裝中文字形)二、如何去掉演算法中的豎線?加入\SetAlgoNoLine 指令在\begin{algorithm}之後排版效果圖:三、還可以使用其他標題樣式?也可以使用\usepackage[ruled,vlined]{algorithm2e}排版效果圖:關於algorithm2e還有以下一些informationThe algorithm2e LaTeX package conflicts with several others over the use of the algorithm identifier.A common indicator is something like this message: Too many }'s.l.1616 }To resolve the issues, simply put the following just before the inclusion of the algorithm2e package:\makeatletter\newif\if@restonecol\makeatother\let\algorithm\relax\let\endalgorithm\relax。
AlgorithmsRogério Britorbrito@p.br∗June2,2006 Contents1Introduction1 2Environment:algorithmic22.1The Simple Statement.22.2The if-then-else Construct22.3The for Loop (3)2.4The while Loop (4)2.5The repeat-until Loop.42.6The Infinite Loop (5)2.7The Precondition (5)2.8The Postcondition (5)2.9Returning Values (6)2.10Printing Messages (6)2.11Comments (7)2.12An Example (7)2.13Options/Customization8 3Environment:algorithm113.1General (11)3.2An Example (12)3.3Options (13)3.4Customization (13)4References in Algorithms14 5Known Issues151IntroductionThis package provides two environments,algorithmic and algorithm,which are designed to be used together but may,depending on the necessities of the author,be used separately.The algorithmic environment provides an environment for describing al-gorithms and the algorithm environment provides a“float”wrapper for algo-rithms(implemented using algorithmic or some other method at the author’s option).The reason that two environments are provided is to allow the author maximumflexibility.This work may be distributed and/or modified under the conditions of the GNU Lesser General Public License as published by the Free Software Foun-dation(see thefile COPYING included in this package).Currently,this package ∗Sincere thanks go to the original maintainer of this package,Peter Williams,and for being kind enough to allow me to continue with his quite useful work.1consists of threefiles:algorithm.sty,algorithmic.sty and algorithms.tex (the source of this document).This is likely to change in the near future.2The algorithmic EnvironmentWithin an algorithmic a number of commands for typesetting popular algo-rithmic constructs are available.In general,the commands provided can be arbitrarily nested to describe quite complex algorithms.An optional argument to the\begin{algorithmic}statement can be used to turn on line numbering by giving a positive integer indicating the required frequency of line number-ing.For example,\begin{algorithmic}[5]would cause everyfifth line to be numbered.2.1The Simple StatementThe simple statement takes the form\STATE<text>and is used for simple statements,e.g.\begin{algorithmic}\STATE$S\leftarrow0$\end{algorithmic}would produceS←0and with line numbering selected for every line using\begin{algorithmic}[1]\STATE$S\leftarrow0$\end{algorithmic}would produce1:S←0For users of earlier versions of algorithmic this construct is a cause of an incompatibility.In the earlier version,instead of starting simple statements with the\STATE command,simple statements were entered as free text and terminated with\\command.Unfortunately,this simpler method failed to survive the modifications necessary for statement numbering.However,the\\ command can still be used to force a line break within a simple statement. 2.2The if-then-else ConstructThe if-then-else construct takes the forms.2\IF{<condition>}<text>\ENDIF\IF{<condition>}<text1>\ELSE<text2>\ENDIF\IF{<condition1>}<text1>\ELSIF{<condition2>}<text2>\ELSE<text3>\ENDIF In the third of these forms there is no limit placed on the number of\ELSIF{<C>}that may be used.For example,\begin{algorithmic}\IF{some condition is true}\STATE do some processing\ELSIF{some other condition is true}\STATE do some different processing\ELSIF{some even more bizarre condition is met}\STATE do something else\ELSE\STATE do the default actions\ENDIF\end{algorithmic}would produceif some condition is true thendo some processingelse if some other condition is true thendo some different processingelse if some even more bizarre condition is met thendo something elseelsedo the default actionsend ifwith appropriate indentations.2.3The for LoopThe for loop takes the forms.\FOR{<condition>}<text>\ENDFOR\FORALL{<condition>}<text>\ENDFORFor example,\begin{algorithmic}\FOR{$i=0$to$10$}\STATE carry out some processing\ENDFOR\end{algorithmic}producesfor i=0to10do3carry out some processingend forand\begin{algorithmic}[1]\FORALL{$i$such that$0\leq i\leq10$} \STATE carry out some processing\ENDFOR\end{algorithmic}produces1:for all i such that0≤i≤10do2:carry out some processing3:end for2.4The while LoopThe while loop takes the form.\WHILE{<condition>}<text>\ENDWHILE For example,\begin{algorithmic}\WHILE{some condition holds}\STATE carry out some processing\ENDWHILE\end{algorithmic}produceswhile some condition holds docarry out some processingend while2.5The repeat-until LoopThe repeat-until loop takes the form.\REPEAT<text>\UNTIL{<condition>}For example,\begin{algorithmic}\REPEAT\STATE carry out some processing\UNTIL{some condition is met}\end{algorithmic}producesrepeatcarry out some processinguntil some condition is met42.6The Infinite LoopThe infinite loop takes the form.\LOOP<text>\ENDLOOPFor example,\begin{algorithmic}\LOOP\STATE this processing will be repeated forever\ENDLOOP\end{algorithmic}producesloopthis processing will be repeated foreverend loop2.7The PreconditionThe precondition(that must be met if an algorithm is to correctly execute) takes the form:\REQUIRE<text>For example,\begin{algorithmic}\REQUIRE$x\neq0$and$n\geq0$\end{algorithmic}producesRequire:x=0and n≥02.8The PostconditionThe postcondition(that must be met after an algorithm has correctly executed) takes the form:\ENSURE<text>For example,\begin{algorithmic}\ENSURE$x\neq0$and$n\geq0$\end{algorithmic}producesEnsure:x=0and n≥052.9Returning ValuesThe algorithmic environment offers a special statement for explicitly returning values in algorithms.It has the syntax:\RETURN<text>For example,\begin{algorithmic}\RETURN$(x+y)/2$\end{algorithmic}producesreturn(x+y)/22.9.1The“true”and“false”ValuesSince many algorithms have the necessity of returning true or false values, algorithms,starting with version2006-06-02,includes the keywords\TRUE and \FALSE,which are intented to print the values in a standard fashion,like the following snippet of an algorithm to decide if an integer n is even or odd:\begin{algorithmic}\IF{$n$is odd}\RETURN\TRUE\ELSE\RETURN\FALSE\ENDIF\end{algorithmic}The code above produces the following output:if n is odd thenreturn trueelsereturn falseend if2.10Printing MessagesAnother feature of the algorithmic environment is that it currently provides a standard way of printing values(which is an operation used enough to merit its own keyword).It has the syntax:\PRINT<text>For example,\begin{algorithmic}\PRINT\texttt{‘‘Hello,World!’’}\end{algorithmic}6producesprint‘‘Hello,World!’’2.11CommentsComments may be inserted at most points in an algorithm using the form:\COMMENT{<text>}For example,\begin{algorithmic}\STATE do something\COMMENT{this is a comment}\end{algorithmic}producesdo something{this is a comment}Because the mechanisms used to build the various algorithmic structures make it difficult to use the above mechanism for placing comments at the end of thefirst line of a construct,the commands\IF,\ELSIF,\ELSE,\WHILE,\FOR, \FORALL,\REPEAT and\LOOP all take an optional argument which will be treated as a comment to be placed at the end of the line on which they appear.For example,repeat{this is comment number one}if condition one is met then{this is comment number two}do somethingelse if condition two is met then{this is comment number three}do something elseelse{this is comment number four}do nothingend ifuntil hell freezes over2.12An ExampleThe following example demonstrates the use of the algorithmic environment to describe a complete algorithm.The following input\begin{algorithmic}\REQUIRE$n\geq0$\ENSURE$y=x^n$\STATE$y\Leftarrow1$\STATE$X\Leftarrow x$\STATE$N\Leftarrow n$\WHILE{$N\neq0$}\IF{$N$is even}\STATE$X\Leftarrow X\times X$7\STATE$N\Leftarrow N/2$\ELSE[$N$is odd]\STATE$y\Leftarrow y\times X$\STATE$N\Leftarrow N-1$\ENDIF\ENDWHILE\end{algorithmic}will produceRequire:n≥0Ensure:y=x ny⇐1X⇐xN⇐nwhile N=0doif N is even thenX⇐X×XN⇐N/2else{N is odd}y⇐y×XN⇐N−1end ifend whilewhich is an algorithm forfinding the value of a number taken to a non-negative power.2.13Options and CustomizationThere is a single option,noend that may be invoked when the algorithmic package is loaded.With this option invoked the end statements are omitted in the output.This allows space to be saved in the output document when this is an issue.2.13.1Changing IndentationIn the spirit of saving vertical space(which is especially important when sub-mitting a paper for a journal,where space is frequently limited for authors), the algorithmic environment offers,beginning with the version released in 2005-05-08,a way to control the amount of indentation that is used by a given algorithm.The amount of indentation to be used is given by the command\algsetup{indent=lenght}where length is any valid length used by T E X.The default value of the indenta-tion used by the algorithmic environment is1em(for“backward compatibility reasons”),but a value of2em or more is recommended,depending on the pub-lication.For example,the snippet8\algsetup{indent=2em}\begin{algorithmic}[1]\STATE$a\Leftarrow1$\IF{$a$is even}\PRINT‘‘$a$is even’’\ELSE\PRINT‘‘$a$is odd’’\end{algorithmic}produces1:a⇐12:if a is even then3:print“a is even”4:else5:print“a is odd”6:end ifwhile\algsetup{indent=5em}\begin{algorithmic}[1]\STATE$a\Leftarrow1$\IF{$a$is even}\PRINT‘‘$a$is even’’\ELSE\PRINT‘‘$a$is odd’’\end{algorithmic}would produce1:a⇐12:if a is even then3:print“a is even”4:else5:print“a is odd”6:end ifThe intended use of this option is to allow the author to omit the end(see Section2.13for details)statements without loosing readability,by increasing the amount of indentation to a suitable level.2.13.2Changing Line NumberingAs mentioned in Section2and illustrated in Section2.13.1,algorithms already provides you with the possibility of numbering lines.Starting with the version released in2005-07-05,you can now change two aspects of line numbering:the size of the line numbers(which,by default,is \footnotesize)and the delimiter used to separate the line number from the code(which,by default,is:,i.e.,a colon).You can change the size of the line numbers using the command:9\algsetup{linenosize=size}where size is any of the various commands provided by L A T E X to change the size of the font to be used.Among others,useful values are\tiny,\scriptsize, \footnotesize and\small.Please see the complete list of sizes in your L A T E X documentation.As another frequently requested feature,you can change the delimiter used with the line numbers by issuing the command:\algsetup{linenodelimiter=delimiter}where delimiter is any“well-formed”string,including the empty string.With this command,you can change the colon to a period(.)by issuing the command \algsetup{linenodelimiter=.}or even omit the delimiter,by specifying the empty string or a space(\), whatever seems best for your document.As an example of such commands,the code produced by\algsetup{linenosize=\small,linenodelimiter=.}\begin{algorithmic}[1]\STATE$i\leftarrow10$\RETURN$i$\end{algorithmic}would be something like1.i←102.return i2.13.3CustomizationIn order to facilitate the use of this package with foreign languages,all of the words in the output are produced via redefinable macro commands.The default definitions of these macros are:\newcommand{\algorithmicrequire}{\textbf{Require:}}\newcommand{\algorithmicensure}{\textbf{Ensure:}}\newcommand{\algorithmicend}{\textbf{end}}\newcommand{\algorithmicif}{\textbf{if}}\newcommand{\algorithmicthen}{\textbf{then}}\newcommand{\algorithmicelse}{\textbf{else}}\newcommand{\algorithmicelsif}{\algorithmicelse\\algorithmicif} \newcommand{\algorithmicendif}{\algorithmicend\\algorithmicif}\newcommand{\algorithmicfor}{\textbf{for}}\newcommand{\algorithmicforall}{\textbf{for all}}10\newcommand{\algorithmicdo}{\textbf{do}}\newcommand{\algorithmicendfor}{\algorithmicend\\algorithmicfor}\newcommand{\algorithmicwhile}{\textbf{while}}\newcommand{\algorithmicendwhile}{\algorithmicend\\algorithmicwhile} \newcommand{\algorithmicloop}{\textbf{loop}}\newcommand{\algorithmicendloop}{\algorithmicend\\algorithmicloop} \newcommand{\algorithmicrepeat}{\textbf{repeat}}\newcommand{\algorithmicuntil}{\textbf{until}}\newcommand{\algorithmicprint}{\textbf{print}}\newcommand{\algorithmicreturn}{\textbf{return}}\newcommand{\algorithmictrue}{\textbf{true}}\newcommand{\algorithmicfalse}{\textbf{false}}If you would like to change the definition of these commands to another con-tent,then you should use,in your own document,the standard L A T E X command renewcommand,with an usage like this:\renewcommand{\algorithmicrequire}{\textbf{Input:}}\renewcommand{\algorithmicensure}{\textbf{Output:}}About the Way Comments Are Formatted The formatting of commentsis implemented via a single argument command macro which may also be rede-fined.The default definition is\newcommand{\algorithmiccomment}[1]{\{#1\}}and another option that may be interesting for users familiar with C-like lan-guages is to redefine the comments to be\renewcommand{\algorithmiccomment}[1]{//#1}Comments produced this way would be like this:i←i+1//Increments iThis second way to present comments may become the default in a future versionof this package.3The algorithm Environment3.1GeneralWhen placed within the text without being encapsulated in afloating environ-ment algorithmic environments may be split over a page boundary,greatly detracting from their appearance.1In addition,it is useful to have algorithms numbered for reference and for lists of algorithms to be appended to the list of contents.The algorithm environment is meant to address these concerns by providing afloating environment for algorithms.1This is the expected behaviour forfloats in L A T E X.If you don’t care about having your algorithm split between pages,then one option that you have is to ignore the algorithm environment.113.2An ExampleTo illustrate the use of the algorithm environment,the following text\begin{algorithm}\caption{Calculate$y=x^n$}\label{alg1}\begin{algorithmic}\REQUIRE$n\geq0\vee x\neq0$\ENSURE$y=x^n$\STATE$y\Leftarrow1$\IF{$n<0$}\STATE$X\Leftarrow1/x$\STATE$N\Leftarrow-n$\ELSE\STATE$X\Leftarrow x$\STATE$N\Leftarrow n$\ENDIF\WHILE{$N\neq0$}\IF{$N$is even}\STATE$X\Leftarrow X\times X$\STATE$N\Leftarrow N/2$\ELSE[$N$is odd]\STATE$y\Leftarrow y\times X$\STATE$N\Leftarrow N-1$\ENDIF\ENDWHILE\end{algorithmic}\end{algorithm}produces Algorithm1which is a slightly modified version of the earlier algorithm for determining the value of a number taken to an integer power.In this case, provided the power may be negative provided the number is not zero.12Algorithm1Calculate y=x nRequire:n≥0∨x=0Ensure:y=x ny⇐1if n<0thenX⇐1/xN⇐−nelseX⇐xN⇐nend ifwhile N=0doif N is even thenX⇐X×XN⇐N/2else//N is oddy⇐y×XN⇐N−1end ifend whileThe command\listofalgorithms may be used to produce a list of algo-rithms as part of the table contents as shown at the beginning of this document. An auxiliaryfile with a suffix of.loa is produced when this feature is used. 3.3OptionsThe appearance of the typeset algorithm may be changed by use of the options: plain,boxed or ruled during the loading of the algorithm package.The default option is ruled.The numbering of algorithms can be influenced by providing the name of the document component within which numbering should be recommenced. The legal values for this option are:part,chapter,section,subsection, subsubsection or nothing.The default value is nothing which causes algo-rithms to be numbered sequentially throughout the document.3.4CustomizationIn order to facilitate the use of this package with foreign languages,methods have been provided to facilitate the necessary modifications.The title used in the caption within algorithm environment can be set by use of the standard\floatname command which is provided as part of the float package which was used to implement this package.For example,\floatname{algorithm}{Procedure}13would cause Procedure to be used instead of Algorithm within the caption of algorithms.In a manner analogous to that available for the built infloating environments, the heading used for the list of algorithms may be changed by redefining the command listalgorithmname.The default definition for this command is\newcommand{\listalgorithmname}{List of Algorithms}3.4.1Placement of AlgorithmsOne important fact that many users may not have noticed is that the algorithm environment is actually built with the float package and float,in turn,uses David Carlisle’s here style option.This means that thefloats generated by the algorithm environment accept a special option,namely,[H],with a capital‘H’, instead of the usual‘h’offered by plain L A T E X.This option works as a stronger request of“please put thefloat here”:instead of just a suggestion for L A T E X,it actually means“put thisfloat HERE”,which is something desired by many.The two algorithms typeset in this document use this option.Warning.You can’t use the‘H’positioning option together with the usual‘h’(for“here”),‘b’(for“bottom”)etc.This is a limitation(as far as I know)of the float.sty package.4Labels and References in AlgorithmsWith the release of2005-07-05,now algorithmic accepts labels and references to specific lines of a given algorithm,so you don’t have to hardcode the line numbers yourself when trying to explain what the code does in your texts. Thanks to Arnaud Legrand for the suggestion and patch for this highly missed feature.An example of its use is shown in Algorithm2.14Algorithm2Calculate y=x nRequire:n≥0∨x=0Ensure:y=x n1:y⇐12:if n<0then3:X⇐1/x4:N⇐−n5:else6:X⇐x7:N⇐n8:end if9:while N=0do10:if N is even then11:X⇐X×X12:N⇐N/213:else14:y⇐y×X15:N⇐N−116:end if17:end whileSee that,in line10,we deal with the case of N being even,while,in line13, we give treatment to the case of N being odd.The numbers you see on this document were generated automatically from the source document.5Issues Between algorithms and tocbibind or memoirIt has been discussed in late2005that algorithms may have bad interactions with the tocbibind or the memoir package(which includes tocbibind).A workaround has been suggested for the problem.After including some-thing like\usepackage[nottoc]{tocbibind}in the preamble of your document,you can put,after\begin{document},the following snippet of code:\renewcommand{\listofalgorithms}{\begingroup\tocfile{List of Algorithms}{loa}\endgroup}\makeatletter\let\l@algorithm\l@figure\makeatotherwhich should make the command\listofalgorithms work as expected.15。