algorithm2e.sty 88.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122
%  algorithm2e.sty --- style file for algorithms
%% Copyright 1996-2005 Christophe Fiorio
%
% This program may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions of LaTeX 
% version 1999/12/01 or later.
%
% This program consists of the files algorithm2e.sty and algorithm2e.tex
%  
%  Report bugs and comments to:
%  fiorio@lirmm.fr
%
%  $Id: algorithm2e.sty,v 3.9 2005/10/04 12:34:52 fiorio Exp $
%
%  PACKAGES REQUIRED:
%
%  - float  (in contrib/supported/float)
%  - ifthen (in base)
%  - xspace (in packages/tools)
%
%%%%%%%%%%%%%%%  Release 3.9
%
%   History: 
%
%   - October  04 2005  - revision 3.9 -
%                      * ADD: - \setalcaphskip command which set the horizontal skip before Algorithm: in caption when
%                               used in ruled algorithm.
%                      * ADD: - SetAlgoInsideSkip command which allows to add an extra vertical space before and after
%                               the core of the algorithm (ie: \SetAlgoInsideSkip{bigskip}) 
%                      * CHANGE: - caption, when used with figure option, is no more controlled by algorithm2e package
%                                  and so follows the exact behaviour of figures. The drawback is that you cannot change
%                                  the typo with AlTitleFnt or CapFnt. The avantage is that if you use caption package,
%                                  it works.
%                      * FIX: - problem with numbering line and pdflatex
%                      * FIX: - error when algorithm2e package was used with beamer and listings together
%   - February 12 2005  - revision 3.8 -
%                      * FIX: - extra line with noend option.
%   - February 10 2005  - revision 3.7 -
%                      * ADD: - sidecomment: different macros allowing to put text right after code
%                               on the same line. They are defined in the same time comment macros
%                               are defined with a star after the macro name. By default comments
%                               are right justified but this can be change with appropriate option
%                               in the macro. Ex:
%                               . default: \tcc*{side comment}
%                               . same as previous: \tcc*[r]{side comment}
%                               . left justify: \tcc*[l]{side comment}
%                               . here: \tcc*[h]{side comment} don't put the end of line mark before
%                                       comment (; by default) and don't end the line.
%                               . flushed: \tcc*[f]{side comment} same as the precedent but right
%                                 justified
%                      * ADD: - scright OPTION (default): right justified side comments (side comments
%                               are flushed to the righr)
%                      * ADD: - scleft OPTION: left justified side comments (side comments are
%                               put right after the code line)
%                      * ADD: - \SetSideCommentLeft acts as scleft option
%                      * ADD: - \SetSideCommentRight acts as scright option
%                      * ADD: - block like macro side text: all macro defining a block allows now
%                               to put text right after key words by putting text into (). Done to
%                               be used with sidecomment macros, but all text can be used. Ex:
%                               \eIf(\tcc*[f]{then comment}){test}{then text}(else side text){else text}
%                      * ADD: - fillcomment OPTION (default): end mark of comment is flushed to the
%                               right so comments fill all the width of text
%                      * ADD: - nofillcomment OPTION: end mark of comment is put right after the
%                               comment
%                      * ADD: - \SetNoFillComment acts as nofillcomment option.
%                      * ADD: - \SetFillComment acts as fillcomment option.
%                      * ADD: - dotocloa OPTION which adds an entry in the toc for the list of
%                               algorithms. This option load package tocbibind if not already done
%                               and so list of figures 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.
%                      * FIX: - vertical spacing for uif macro with noend option
%                      * FIX: - all the compatibility problems between caption and other packages
%                      * FIX: - typographical differences between list of algorithms and other lists
%                               when in report or book 
%
%   - January 24 2005  - revision 3.6 -
%                      * FIX: - vertical spacing and space characters at the beginning or end of
%                               comments.
%                               line numbers of comments not in the nlsty.
%                               Thanks to Arnaud Giersch for his comments and suggestions.
%                      * FIX: - Set*Sty macro: the styles defined was not protected and was modified
%                               by surrounding context. For example KwTo in a \For{}{} was in bold AND
%                               italic instead of just in bold.
%                      * FIX: - line number misplacement after \Indp
%
%   - January 21 2005  - revision 3.5 -
%                      * ADD: - hidden numbering of the lines. Lines are auto-numbered but numbers
%                               are shown only on lines you specify:
%                               * linesnumberedhidden option or \linesnumberedhidden macro activate
%                                 this functionnality.
%                               * \showln and \showlnlabel{lab} macros make the number visible on
%                                 the line. \showlnlabel{lab} allows to set a label for this line.
%                               Thanks to Samson de Jager who makes this suggestion and provides the
%                               macros.
%                      * ADD: - \AlCapFnt and \SetAlCapFnt which allow to have a different font for
%                               caption. Works like \AlFnt and \SetAlFnt and by default is the same.
%                      * ADD: - \AlCapSkip skip length. This vertical space is added before caption
%                               in plain ou boxed mode. It allows to change distance between text
%                               and caption.
%                      * FIX: - caption compatible with IEEEtran class. 
%                      * FIX: - some vertical spacing error with \uIf macros (Thanks to Arnaud Giersch)
%                      * FIX: - Procedure and Function: lines are also numbered like algorithms
%                      * FIX: - CommentSty was not used for Comments
%
%   - January 10 2005  - revision 3.4 -
%                      * FIX: - caption compatible with new release of Beamer class. 
%
%   - June 16 2004     - revision 3.3 - 
%                      * FIX: - Hyperlink references of Hyperref package works now if compiled with pdflatex 
%                               and [naturalnames] option of hyperref package is used.
%                      * FIX: - algorithm[H] had problem in an list environment - corrected
%                      * FIX: - interline was not so regular in nested blocks - corrected
%                      * ADD  - \Setvlineskip macro which set the vertical skip after the little horizontal 
%                               rule which closes a block in Vlined mode. By default 0.8ex
%
%   - June 11 2004     - revision 3.2 - AUTO NUMBERING LINES !!!
%                      * ADD: auto numbering of the lines (the so asked and so long awaiting feature)
%                             this feature is managed by 3 options and 3 commands:
%                             - linesnumbered option: lines of the algo are numbered except for comments and
%                               input/output (KwInput and KwInOut)
%                             - commentsnumbered option: makes comments be numbered
%                             - inoutnumbered option: makes data input/output be numbered
%                             - \nllabel{lab} labels the line so you can cite with \ref{lab}
%                             - \linesnumbered make the following algorithms having auto-numbered lines
%                             - \linesnotnumbered make the following algorithms having no auto-numbered lines
%                      * Change: algo2e option renames listofalgorithm in listofalgorithme
%                      * FIX: new solution for compatibility with color package, more robust and not tricky.
%                             Many thanks to David Carlisle for his advices
%
%   - June 09 2004     - revision 3.1 -
%                      * Change: \SetKwSwitch command defines an additionnal
%                                macro \uCase and \Case prints end
%                      * Change: now macros SetKw* do a renewcommand if the
%                                keyword is already defined. So you can redefine
%                                default definition at your own convenience or
%                                change your definition without introducing a
%                                new macro and changing your text.
%                      * ADD: new macro \SetKwIF which do \SetKwIf and
%                             \SetKwIfElseIf.The following default definition has been added:
%                             \SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}
%                             and so you get the macros;
%                             \If \eIf \lIf \uIf \ElseIf \uElseIf \lElseIf \Else
%                             \uElse \lElse
%                      * ADD: new macro \SetAlgoSkip which allow to fix the
%                             vertical skip before and after the algorithms.
%                             Default is smallskip, do \SetAlgoSkip{} if you
%                             don't want an extra space or \SetAlgoSkip{medskip}
%                             or \SetAlgoSkip{bigskip} if you want bigger space.
%                      * ADD: macro \SetKwIf defines in addition a new macro
%                             \uElse  (depending on wat name you
%                             have given in #2 arg).
%                      * ADD: macro \SetKwIfElseIf defines in addition a new macro
%                             \uElse and \ugElseIf (depending on what name you
%                             have given in #2 and #3 arg).
%                      * Change: baseline of algorithm is now top, so two
%                                algorithms can be put side by side.
%                      * FIX: Compatibility with color package solved. The problem
%                             was due to a redefinition of standard macros by color package
%                             This solves compatibility problem with other packages
%                             as pstcol or colortbl.
%                             (notified by Dirk Fressmann, Antti Tarvainen and Koby Crammer)
%                      * Fix: extra little shift to the right with boxed style
%                             algorithm removed (notified by P. Tanovski)
%                      * Fix: algoln option was buggy (notified bye Jiaying Shen)
%                      * Fix: german and portuges option didn't work due to bad
%                             typo (notified by Martin Sievers, Thorsten Vitt
%                             and Jeronimo Pellegrini)
%                      
%   - February 13 2004 - revision 3.0 -
%                      * Major revision which makes the package independent from
%                        float.sty, so now
%                        - algorithm* works better, in particular can be used in
%                          multicols environments
%                        - (known bug corrected)
%                          [H] works now for all sort of environment but is
%                          handled differently for classic environment and star
%                          environment (algorithm, figure, procedure and
%                          function). For star environment, H acts like for
%                          classical figure environment, so it doesn't stay here
%                          absolutely.
%                        - (known bug corrected)
%                          you can use now floatflt package with algorithm
%                          package and even with figure option. Beware that if
%                          you want to put an algorithm inside a floatingfigure,
%                          it cannot be floating, so [H] is required and then
%                          figure option should not be used, since standard
%                          figure[H] are still floating with LaTeX.
%                      * boxruled: a new style added. Possible now since no
%                        style no more defined by the float package.
%                      * nocaptionofalgo: dosen't print Algorithm #: in the
%                        caption for algorithm in ruled or algoruled style.
%                        note: this is just documentation of a macro which was
%                        already in the package.
%   - December 14 2003 - revision 2.52 -
%                      * output message shorter
%                      * french keyword macro \PourTous was missing for
%                        longend option, it has been added.
%                      * TitleofAlgo prints Function or Procedure in
%                        corresponding environments.
%
%   - October 27 2003  - revision 2.51 - Revision submitted to CTAN archive
%                      * correction of a minor which make caption in procedure
%                        and function to be blanck with pdfscreen package
%                        (thanks to Joel Gossens for the notification)
%                      * add two internal definition to avoid some errors when
%                        used with Hyperref package (Hyperref package need to
%                        define new counter macro from existing ones, and
%                        don't do it for algorithm2e package, so we do it)
%
%   - October 17 2003  - revision 2.50 - first revision for CTAN archive
%
%                      * add \AlFnt and \SetAlFnt{font} macros:
%                        \AlFnt is used at the beginning of the caption and 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 algorithm. For 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.
%                      * add \AlTitleFnt{text} and \SetAlTitleFnt{font} macros:
%                        The {Algorithm: } in the caption is typeset with
%                        \AlTitleFnt{Algorithm:}. You can use it to have text
%                        typeset as {Algorithm:} of captions. Default is
%                        textbf.
%                        Default can be redefined by \SetAlTitleFnt{font}.
%                      * add CommentSty typo for text comment.
%                      * add some compatibility with hyperref package (still
%                        an error on multiply defined refs but pdf correctly
%                        generated)
%                      * flush text to left in order to have correct
%                        indentation even with class as amsart which center
%                        all figures
%                      * add german, portugues and czech options for title of
%                        algorithms and typo.
%                      * add portuguese translation of predefined keywords
%                      * add czech translation of some predefined keywords
%
%   - December 23 2002 - revision 2.40
%                      * add some french keyword missing
%                      * add function* and procedure* environment like
%                        algorithme* environment: print in one column even
%                        if twocolumn option is specified for the document.
%                      * add a new macro \SetKwComment to define macro which
%                        writes comments in the text. First argument is the
%                        name of the macro, second is the text put before the
%                        comment, third is the text put at the end of the
%                        comment.Default are \tcc and \tcp
%                      * add new options to change the way algo are numbered:
%                        [algopart] algo are numbered within part (counter must exist)
%                        [algochapter] algo are numbered within chapter
%                        [algosection] algo are numbered within section
%
%   - March 27 2002   - revision 2.39
%                      * Gilles Geeraerts: added the \SetKwIfElseIf to manage
%                        if (c)
%                             i;
%                        else if (c)
%                             i;
%                        ...
%                        else
%                             i;
%                        end
%                      * Also added \gIf \gElsIf \gElse.
%
%   - January 02 2001 - revision 2.38
%                      * bugs related to the caption in procedure and function
%                        environment are corrected.
%                      * bug related to option noend (extra vertical space added
%                        after block command as If or For) is corrected.
%                      * czech option language added (thanks to Libor Bus: l.bus@sh.cvut.cz).
%  
%   - October 16 2000 - revision 2.37
%                      * option algo2e added: change the name of environment
%                        algorithm into algorithm2e. So allow to use the package
%                        with some journal style which already define an algorithm
%                        environment.
%  
%   - September 13 2000 - revision 2.36
%                      * option slide added: require package color
%                      * Hack for slide class in order to have correct
%                        margins
%  
%   - November 25 1999 - revision 2.35
%                      * revision number match RCS number
%                      * Thanks to David A. Bader, a new option is added:
%                        noend: no end keywords are printed.
%  
%   - November 19 1999 - revision 2.32
%                      * minor bug on longend option corrected.
%  
%   - August 26 1999 - revision 2.31
%                      * add an option : figure
%                        this option makes algorithms be figure and so are numbered
%                        as figures, have Figure as caption and are put in 
%                        the \listoffigures
%  
%   - January 21 1999 - revision 2.3 beta
%                    add 2 new environments: procedure and function.
%                    These environments works like algorithm environment but:
%                    - the ruled (or algoruled) style is imperative.
%                    - the caption now writes Procedure name....
%                    - the syntax of the \caption command is restricted as
%                      follow: you MUST put a name followed by 2 braces like
%                      this ``()''. You can put arguments inside the braces and
%                      text 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 procedure or function as reference (not
%                      the number like a classic algorithm environment).
%                    There are also two new styles : ProcNameSty and
%                    ProcArgSty. These style are by default the same as FuncSty
%                    and ArgSty but are used in the caption of a procedure or a
%                    function.
%                    
%   - November 28 1996 - revision 2.22
%                    add a new macro \SetKwInParam{arg1}{arg2}{arg3}:
%                    it defines a macro \arg1{name}{arg} which prints name in keyword
%                    style followed byt arg surrounded by arg2 and arg3. The main
%                    application is to a function working as \SetKwInput to be used
%                    in the head of the algorithm. For example
%                    \SetKwInParam{Func}{(}{)} allows
%                    \Func{functionname}{list of arguments} which prints:
%                    \KwSty{functioname(}list of arguments\KwSty{)}
%       
%
%   - November 27 1996 - revision 2.21 :
%                    minor bug in length of InOut boxes fixed.
%                    add algorithm* environment.
%
%   - July 12 1996 - revision 2.2 : \SetArg and \SetKwArg macros removed.
%                        
%                    \SetArg has been removed since it never has been
%                    documented.
%                    \SetKwArg has been removed since \SetKw can now
%                    take an argument in order to be consistent with
%                    \SetKwData and \SetKwFunction macros.
%
%   - July 04 1996 - revision 2.1 : still more LaTeX2e! Minor compatibility break
%
%                    Macros use now \newcommand instead of \def, use of \setlength, 
%                    \newsavebox, ... and other LaTeX2e specific stuff.
%                    The compatibility break:
%                    - \SetData becomes \SetKwData to be more consistent. So the old 
%                      \SetKwData becomes \SetKwInput
%                    - old macros \titleofalgo, \Freetitleofalgo and \freetitleofalgo
%                      from LaTeX209 version which did print a warning message and call 
%                      \Titleofalgo in version 2.0 are now removed!
%
%   - March 13 1996 - revision 2.0: first official major revision.
%   
%
%%%%%%%%%%%%%%
%
%   Known bugs: 
%   -----------
%   - no more known bugs... all are corrected!
%
%%%%%%%%%%%%%%
%
%   Package options: 
%   ---------------
%   - french, english, german, portuguese, czech  : for the name of the algorithm, e.g.
%   - boxed, boxruled, ruled, algoruled, plain    : layout of the algorithm
%   - algo2e                           : environment is algorithm2e instead of algorithms 
%                                        and \listofalgorithmes instead of \listofalgorithms
%   - slide                            : to use when making slides
%   - noline,lined,vlined              : how block are designed.
%   - linesnumbered                    : auto numbering of the algorithm's lines
%   - algopart,algochapter,algosection : algo numbering within part, chapter or section
%   - titlenumbered,titlenotnumbered   : numbering of title set by \Titleofalgo
%   - figure                           : algorithms are figures, numbered as figures, and put in the list of figures.
%   - resetcount, noresetcount         : start value of line numbers.
%   - algonl                           : line numbers preceded by algo number
%   - shortend, longend, noend         : short or long end keyword as endif for e.g.
%  
%   defaults are; english,plain,resetcount,titlenotnumbered
%
%%%%%%%%%%%%%%
%
%   Short summary  
%   -------------
%  
%   algorithm is an environment for writing algorithm in LaTeX2e
%   It provide macros that allow you to create differents
%   sorts of key words, therefore a set of predefined key word
%   is gived.
%
%   IT should be used as follows
%
%   \begin{algorithm}
%       ...
%       ...
%   \end{algorithm}
%
%
%   IMPORTANT : each line MUST end with \;
%
%   Note that if you define macros outside algorithm environment they
%   are avaible in all the document and particulary you can use then
%   inside all algorithms without re-define them.
%  
%   an example:
%
%   \begin{algorithm}[H]
%     \SetLine
%     \AlgData{this text}
%     \AlgResult{how to write algorithm with \LaTeX2e }
%     
%     initialization\;
%     \While{not at end of this document}{
%       read current section\;
%       \eIf{understand}{
%         go to next section\;
%         current section becomes this one\;
%         }{
%         go back to the beginning of current section\;
%         }
%       }
%     \caption{How to write algorithm}
%   \end{algorithm}
%
%
%%%%%%%%%%%%%%         predefined english keywords
%
%     \AlgData{input}
%     \AlgResult{output}
%     \KwIn{input}
%     \KwOut{output}
%     \KwData{input}
%     \KwResult{output}
%     \Ret{[value]}
%     \KwTo                                       % a simple keyword
%     \Begin{block inside}
%     \If{condition}{Then block}                  % in a block
%     \uIf{condition}{Then block}                 % in a block unended
%     \Else{inside Else}                          % in a block
%     \eIf{condition}{Then Block}{Else block}     % in blocks
%     \lIf{condition}{Else text}                  % on the same line
%     \lElse{Else text}                           % on the same line        
%     \Switch{Condition}{Switch block}
%     \Case{a case}{case block}                   % in a block
%     \lCase{a case}{case text}                   % on the same line
%     \Other{otherwise block}                     % in a block
%     \lOther{otherwise block}                    % on the same line
%     \For{condition}{text loop}                  % in a block
%     \lFor{condition}{text}                      % on the same line
%     \ForEach{condition}{text loop}              % in a block
%     \lForEach{condition}{text}                  % on the same line
%     \Repeat{End condition}{text loop}           % in a block
%     \lRepeat{condition}{text}                   % on the same line
%     \While{condition}{text loop}                % in a block
%     \lWhile{condition}{text loop}               % on the same line
%
%
%%%%%%%%%%%%%%        predefined french keywords
%
%     \AlgDonnees{input}
%     \AlgRes{input}
%     \Donnees{input}
%     \Res{input}
%     \Retour[valeur]}
%     \Deb{block inside}
%     \KwA                                          % un mot clef simple
%     \Si{condition}{Bloc du Alors}                 % Dans un bloc
%     \uSi{condition}{Bloc du Alors}                % Dans un bloc non termine
%     \eSi{condition}{Bloc du Alors}{Bloc du Sinon} % Dans un bloc
%     \lSi{condition}{texte du Alors}               % sur la meme ligne
%     \lSinon{texte du Sinon}                       % sur la meme ligne
%     \Suivant{Condition}{Bloc de l'instruction}
%     \Cas{cas}{Bloc de ce cas}                     % Dans un bloc
%     \lCas{cas}{Bloc de ce cas}                    % sur la meme ligne
%     \Autres{Bloc de l'alternative}                % Dans un bloc
%     \lAutres{Bloc de l'alternative}               % sur la meme ligne
%     \Pour{condition}{texte de la boucle}          % Dans un bloc
%     \lPour{condition}{texte}                      % sur la meme ligne
%     \PourCh{condition}{texte de la boucle}          % Dans un bloc
%     \lPourCh{condition}{texte}                      % sur la meme ligne
%     \Repeter{End condition}{texte de la boucle}   % Dans un bloc
%     \lRepeter{condition}{texte}                   % sur la meme ligne
%     \Tq{condition}{texte de la boucle}            % Dans un bloc
%     \lTq{condition}{texte de la boucle}           % sur la meme ligne
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% for more complete informations you can see algorithm2e.tex
%
%
%%%%%%%%%%%%%%%%%%%%%%%% Identification Part %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
%
\ProvidesPackage{algorithm2e}[2005/10/04 v3.9 algorithms environments]
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%% Initial Code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\@makeother\*% some package redefined it as a letter (as color.sty)
%
% definition of commands which can be redefined in options of the package.
%
\newcounter{AlgoLine}
\setcounter{AlgoLine}{0}
%
\newcommand{\listalgorithmcfname}{}
\newcommand{\algorithmcfname}{}
\newcommand{\algocf@typo}{}
\newcommand{\@algocf@procname}{}
\newcommand{\@algocf@funcname}{}
\newcommand{\@algocf@titleofalgoname}{\algorithmcfname}
\newcommand{\@algocf@algotitleofalgo}{%
  \renewcommand{\@algocf@titleofalgoname}{\algorithmcfname}}
\newcommand{\@algocf@proctitleofalgo}{%
  \renewcommand{\@algocf@titleofalgoname}{\algocf@procname}}
%
\newcommand{\algocf@style}{plain}
\newcommand{\@ResetCounterIfNeeded}{}
\newcommand{\@titleprefix}{}
%
\newcommand{\algocf@numbering}[1]{\newcommand{\algocf@within}{#1}}
%
\newcommand{\defaultsmacros@algo}{\algocf@defaults@shortend}
%
\newcommand{\algocf@list}{loa}
\newcommand{\algocf@float}{algocf}
%
\newcommand{\algocf@envname}{algorithm}
\newcommand{\algocf@listofalgorithms}{listofalgorithms}
%
%
%%%%%%%%%%%%%%%%%%%%%% Declaration of Options %%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\RequirePackage{ifthen}
%
\DeclareOption{algo2e}{%
  \renewcommand{\algocf@envname}{algorithm2e}
  \renewcommand{\algocf@listofalgorithms}{listofalgorithmes}
}
%
\newboolean{algocf@slide}\setboolean{algocf@slide}{false}
\DeclareOption{slide}{%
  \setboolean{algocf@slide}{true}%
}
%
\DeclareOption{figure}{
\renewcommand{\algocf@list}{lof}
\renewcommand{\algocf@float}{figure}
}
%
\DeclareOption{english}{%
\renewcommand{\listalgorithmcfname}{List of Algorithms}%
\renewcommand{\algorithmcfname}{Algorithm}%
\renewcommand{\algocf@typo}{}%
\renewcommand{\@algocf@procname}{Procedure}
\renewcommand{\@algocf@funcname}{Function}
}
%
\DeclareOption{french}{%
\renewcommand{\listalgorithmcfname}{Liste des Algorithmes}%
\renewcommand{\algorithmcfname}{Algorithme}%
\renewcommand{\algocf@typo}{\ }%
\renewcommand{\@algocf@procname}{Procédure}
\renewcommand{\@algocf@funcname}{Fonction}
}
%
\DeclareOption{czech}{%
\renewcommand{\listalgorithmcfname}{Seznam algoritm\v{u}}%
\renewcommand{\algorithmcfname}{Algoritmus}%
\renewcommand{\algocf@typo}{}%
\renewcommand{\@algocf@procname}{Procedura}
\renewcommand{\@algocf@funcname}{Funkce}
}
%
\DeclareOption{german}{%
\renewcommand{\listalgorithmcfname}{Liste der Algorithmen}%
\renewcommand{\algorithmcfname}{Algorithmus}%
\renewcommand{\algocf@typo}{\ }%
\renewcommand{\@algocf@procname}{Prozedur}%
\renewcommand{\@algocf@funcname}{Funktion}%
}
%
\DeclareOption{portugues}{%
\renewcommand{\listalgorithmcfname}{Lista de Algoritmos}%
\renewcommand{\algorithmcfname}{Algoritmo}%
\renewcommand{\algocf@typo}{}%
\renewcommand{\@algocf@procname}{Procedimento}
\renewcommand{\@algocf@funcname}{Fun\c{c}\~{a}o}
}
%
% OPTIONs plain, boxed, ruled, algoruled & boxruled
%
\newcommand{\algocf@style@plain}{\renewcommand{\algocf@style}{plain}}
\newcommand{\algocf@style@boxed}{\renewcommand{\algocf@style}{boxed}}
\newcommand{\algocf@style@ruled}{\renewcommand{\algocf@style}{ruled}}
\newcommand{\algocf@style@algoruled}{\renewcommand{\algocf@style}{algoruled}}
\newcommand{\algocf@style@boxruled}{\renewcommand{\algocf@style}{boxruled}}
\newcommand{\restylealgo}[1]{\csname algocf@style@#1\endcsname}
\DeclareOption{plain}{\algocf@style@plain}
\DeclareOption{boxed}{\algocf@style@boxed}
\DeclareOption{ruled}{\algocf@style@ruled}
\DeclareOption{algoruled}{\algocf@style@algoruled}
\DeclareOption{boxruled}{\algocf@style@boxruled}
%
% OPTIONs algopart,algochapter & algosection
%
\DeclareOption{algopart}{\algocf@numbering{part}}       %algo part numbered
\DeclareOption{algochapter}{\algocf@numbering{chapter}} %algo chapter numbered
\DeclareOption{algosection}{\algocf@numbering{section}} %algo section numbered
%
% OPTIONs resetcount & noresetcount
%
\DeclareOption{resetcount}{\renewcommand{\@ResetCounterIfNeeded}{\setcounter{AlgoLine}{0}}}
\DeclareOption{noresetcount}{\renewcommand{\@ResetCounterIfNeeded}{}}
%
% OPTION linesnumbered
%
\newboolean{algocf@linesnumbered}\setboolean{algocf@linesnumbered}{false}
\newcommand{\algocf@linesnumbered}{\relax}
\DeclareOption{linesnumbered}{%
  \setboolean{algocf@linesnumbered}{true}
  \renewcommand{\algocf@linesnumbered}{\everypar={\nl}}
}
%
% OPTION linesnumberedhidden
%
\DeclareOption{linesnumberedhidden}{%
  \setboolean{algocf@linesnumbered}{true}
  \renewcommand{\algocf@linesnumbered}{\everypar{\stepcounter{AlgoLine}}}
}
%
% OPTION commentsnumbered inoutnumbered
%
\newboolean{algocf@commentsnumbered}\setboolean{algocf@commentsnumbered}{false}
\DeclareOption{commentsnumbered}{\setboolean{algocf@commentsnumbered}{true}}
\newboolean{algocf@inoutnumbered}\setboolean{algocf@inoutnumbered}{false}
\DeclareOption{inoutnumbered}{\setboolean{algocf@inoutnumbered}{true}}
%
% OPTIONs titlenumbered & titlenotnumbered
%
\DeclareOption{titlenumbered}{%
  \renewcommand{\@titleprefix}{%
    \refstepcounter{algocf@float}%
    \AlTitleFnt{\@algocf@titleofalgoname\
      \expandafter\csname the\algocf@float\endcsname\algocf@typo : }}%
}
%
\DeclareOption{titlenotnumbered}{\renewcommand{\@titleprefix}{%
    \AlTitleFnt{\@algocf@titleofalgoname\algocf@typo : }}%
}
%
% OPTIONs lined, vlined & noline
%
\DeclareOption{lined}{\AtBeginDocument{\SetLine}}    % \SetLine
\DeclareOption{vlined}{\AtBeginDocument{\SetVline}}  % \SetVline
\DeclareOption{noline}{\AtBeginDocument{\SetNoline}} % \Setnoline (default)
%
% OPTIONs algonl
% line numbered with the counter of the algorithm
%
\DeclareOption{algonl}{\renewcommand{\theAlgoLine}{\expandafter\csname the\algocf@float\endcsname.\arabic{AlgoLine}}}
%
% OPTIONs longend, shotend & noend
%
\DeclareOption{longend}{%
\renewcommand{\defaultsmacros@algo}{\algocf@defaults@longend}}
\DeclareOption{shortend}{%
\renewcommand{\defaultsmacros@algo}{\algocf@defaults@shortend}}
\newboolean{algocf@optnoend}\setboolean{algocf@optnoend}{false}
\DeclareOption{noend}{%
  \setboolean{algocf@optnoend}{true}%
  \renewcommand{\defaultsmacros@algo}{\algocf@defaults@noend}}
%
% OPTION dotoc
%
\newboolean{algocf@dotocloa}\setboolean{algocf@dotocloa}{false}
\DeclareOption{dotocloa}{%
  \setboolean{algocf@dotocloa}{true}
}
%
% OPTION comments
%
\newboolean{algocf@optfillcomment}\setboolean{algocf@optfillcomment}{true}
\DeclareOption{nofillcomment}{%
  \setboolean{algocf@optfillcomment}{false}%
}
\DeclareOption{fillcomment}{%
  \setboolean{algocf@optfillcomment}{true}%
}
%
% OPTION sidecommments
%
\newboolean{algocf@scleft}\setboolean{algocf@scleft}{false}
\DeclareOption{scleft}{%
  \setboolean{algocf@scleft}{true}%
}
\DeclareOption{sright}{% default
  \setboolean{algocf@scleft}{false}%
}
%
%
%%%%%%%%%%%%%%%%%%%%%%% Execution of Options %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\ExecuteOptions{english,plain,resetcount,titlenotnumbered}
%
\ProcessOptions
%
\@algocf@algotitleofalgo % fix name for \Titleofalgo to \algorithmcfname by default
%
%%%%%%%%%%%%%%%%%%%%%%%%%% Package Loading %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%\RequirePackage{float}[2001/11/08]
%
\RequirePackage{xspace}
%
\ifthenelse{\boolean{algocf@slide}}{\RequirePackage{color}}{}
%

\AtEndOfPackage{%
  \ifthenelse{\boolean{algocf@dotocloa}}{%
    \renewcommand{\listofalgorithmes}{\tocfile{\listalgorithmcfname}{loa}}%
  }{\relax}
}

% if loa in toc required, load tocbibind package if not already done.
\ifthenelse{\boolean{algocf@dotocloa}}{%
  \ifx\@tocextra\undefined%
  \RequirePackage{tocbibind}
  \fi%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Main Part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\newcommand{\algocf@name}{algorithm2e}
\newcommand{\algocf@date}{october 04 2005}
\newcommand{\algocf@version}{Release 3.9}
\newcommand{\algocf@id}{\algocf@version\space -- \algocf@date\space --}
\typeout{********************************************************^^JPackage `\algocf@name'\space\algocf@id^^J%
         - algorithm2e-announce@lirmm.fr  mailing list for announcement about releases^^J%
         - algorithm2e-discussion@lirmm.fr mailing list for discussion about package^^J%
         subscribe by emailing sympa@lirmm.fr with 'subscribe <list> <firstname name>'^^J%
         - Author: Christophe Fiorio (fiorio@lirmm.fr)^^J********************************************************}
%%
%%
%%
%%
%%
%%
%%%% hyperref compatibility tricks: Hyperref package defines H counters from
   % standard counters (i.e \theHpage from \thepage) and check some particular
   % counters of some packages, unfortunately it doesn't do the same for
   % algorithm2e package but act as Hcounter was defined. To avoid errors we
   % defined \theHalgocf ourself
%%%%
% \@ifundefined{theHalgocf}{\def\theHalgocf{\thealgocf}}{}%
% \@ifundefined{theHAlgoLine}{\def\theHAlgoLine{\theAlgoLine}}{}%
% \@ifundefined{theHalgocf}{\def\theHalgocf{\thealgocf}}{}%
% \@ifundefined{theHAlgoLine}{\def\theHAlgoLine{\thealgocf}}{}%
% \@ifundefined{toclevel@algocf}{\def\toclevel@algocf{0}}{}%
%%
%%
%%
\newcommand{\@defaultskiptotal}{0.5em}%\Setnlskip{0.5em}
\newskip\skiptotal\skiptotal=0.5em%\Setnlskip{0.5em}
\newskip\skiprule
\newskip\skiphlne
\newskip\skiptext
\newskip\skiplength
\newskip\algomargin
\newskip\skipalgocfslide\skipalgocfslide=1em
\newdimen\algowidth
\newdimen\inoutsize
\newdimen\inoutline
%
\newcommand{\@algoskip}{\smallskip}%
\newcommand{\SetAlgoSkip}[1]{\renewcommand{\@algoskip}{\csname#1\endcsname}}%
\newcommand{\@algoinsideskip}{\relax}%
\newcommand{\SetAlgoInsideSkip}[1]{\renewcommand{\@algoinsideskip}{\csname#1\endcsname}}%
%
\newsavebox{\algocf@inoutbox}
\newsavebox{\algocf@inputbox}
%%
%%
\newcommand{\arg@e}{}
\newcommand{\arg@space}{\ }
\newcommand{\BlankLine}{\vskip 1ex}
%%
\newcommand{\vespace}{1ex}
\newcommand{\SetInd}[2]{%
\skiprule=#1%
\skiptext=#2%
\skiplength=\skiptext\advance\skiplength by \skiprule\advance\skiplength by 0.4pt}
\SetInd{0.5em}{1em}
\algomargin=\leftskip\advance\algomargin by \parindent
\newcommand{\incmargin}[1]{\advance\algomargin by #1}
\newcommand{\decmargin}[1]{\advance\algomargin by -#1}
\newcommand{\Setnlskip}[1]{%
\renewcommand{\@defaultskiptotal}{#1}%
\setlength{\skiptotal}{#1}}
\newcommand{\setnlskip}[1]{\Setnlskip{#1}}%kept for compatibility issue
%%
\newskip\AlCapSkip\AlCapSkip=0ex
\newskip\AlCapHSkip\AlCapSkip=0ex
\newcommand{\setalcapskip}[1]{\setlength{\AlCapSkip}{#1}}
\newcommand{\setalcaphskip}[1]{\setlength{\AlCapHSkip}{#1}}
\setalcaphskip{.5\algomargin}
%%
%%
\newcommand{\Indentp}[1]{\advance\leftskip by #1}
\newcommand{\Indp}{\advance\leftskip by 1em}
\newcommand{\Indpp}{\advance\leftskip by 0.5em}
\newcommand{\Indm}{\advance\leftskip by -1em}
\newcommand{\Indmm}{\advance\leftskip by -0.5em}
%%
%%
%% Line Numbering
%%
%%
% number line style
\newcommand{\nlSty}[1]{\textnormal{\textbf{#1}}}% default definition
\newcommand{\Setnlsty}[3]{\renewcommand{\nlSty}[1]{\textnormal{\csname#1\endcsname{#2##1#3}}}}
%
%
\newcommand{\algocf@nlhlabel}[2]{%
  \immediate\write\@auxout{%
    \string\newlabel{#1}{%
      {#2}% current label
      {\thepage}% page
      {}% current label string
%      {AlgoLine\thealgocfline.\theAlgoLine}% current Href
      {AlgoLine\thealgocfline.\theAlgoLine}% current Href
      {}%
    }%
  }%
}
%
% nl definitions
%
\newcommand{\nl}{%
  \@ifundefined{href}{% if not hyperref then do a simple refstepcounter
    \refstepcounter{AlgoLine}%
  }{% else if hyperref, do the anchor so 2 lines in two differents algorithms cannot have the same href
%    \stepcounter{AlgoLine}\Hy@raisedlink{\hyper@anchorstart{AlgoLine\thealgocfline.\theAlgoLine}\hyper@anchorend}%
    \stepcounter{AlgoLine}\Hy@raisedlink{\hyper@anchorstart{AlgoLine\thealgocfline.\theAlgoLine}\hyper@anchorend}%
  }% now we can do the line numbering
  \strut\vadjust{\kern-\dp\strutbox\vtop to \dp\strutbox{%
      \baselineskip\dp\strutbox\vss\llap{\scriptsize{\nlSty{\theAlgoLine}\hskip\skiptotal}}\null}}%
}%
\newcommand{\nllabel}[1]{%
  \@ifundefined{href}{\label{#1}}{\algocf@nlhlabel{#1}{\theAlgoLine}}}%
%
\newcommand{\enl}{;%
  \@ifundefined{href}{% if not hyperref then do a simple refstepcounter
    \refstepcounter{AlgoLine}%
  }{% else if hyperref, do the anchor so 2 lines in two differents algorithms cannot have the same href
%    \stepcounter{AlgoLine}\Hy@raisedlink{\hyper@anchorstart{AlgoLine\thealgocfline.\theAlgoLine}\hyper@anchorend}%
    \stepcounter{AlgoLine}\Hy@raisedlink{\hyper@anchorstart{AlgoLine\thealgocfline.\theAlgoLine}\hyper@anchorend}%
  }% now we can do the line numbering
  \hfill\rlap{%
  \scriptsize{\nlSty{\theAlgoLine}}}\par}
\newcommand{\nlset}[1]{%
  \hskip 0pt\llap{%
  \scriptsize{\nlSty{#1}}\hskip\skiptotal}\ignorespaces}
%
% lnl definitions
%
\@ifundefined{href}{% if not hyperref
  \newcommand{\lnl}[1]{\nl\label{#1}\ignorespaces}%
}{%                   else hyperref
  \newcommand{\lnl}[1]{\nl\algocf@nlhlabel{#1}{\theAlgoLine}\ignorespaces}%
}
%
% nlset
%
\@ifundefined{href}{%
  \newcommand{\lnlset}[2]{\nlset{#2}\protected@edef\@currentlabel{#2}\label{#1}}%
}{%else hyperref
  \newcommand{\lnlset}[2]{\nlset{#2}%
    \Hy@raisedlink{\hyper@anchorstart{AlgoLine.#2}\hyper@anchorend}\algocf@nlhlabel{#1}{#2}%
    \ignorespaces%
  }%
}

%
% set char put at end of each line
%
\newcommand{\algocf@endline}{\string;}
\newcommand{\SetEndCharOfAlgoLine}[1]{\renewcommand{\algocf@endline}{#1}}
%
% end of line definition
%
\newcommand{\@endalgoln}{\algocf@endline\par}% default definition: printsemicolon
\newcommand{\dontprintsemicolon}{\renewcommand{\@endalgoln}{\par}}
\newcommand{\printsemicolon}{\renewcommand{\@endalgoln}{\algocf@endline\par}}
%
% line numbering
%
\newcommand{\linesnumbered}{\setboolean{algocf@linesnumbered}{true}\renewcommand{\algocf@linesnumbered}{\everypar={\nl}}}
\newcommand{\linesnotnumbered}{%
  \setboolean{algocf@linesnumbered}{false}%
  \renewcommand{\algocf@linesnumbered}{\relax}%
}
%
\newcommand{\linesnumberedhidden}{%
  \setboolean{algocf@linesnumbered}{true}\renewcommand{\algocf@linesnumbered}{\everypar{\stepcounter{AlgoLine}}}}
\newcommand{\showln}{\nlset{\theAlgoLine}\ignorespaces} % display the line number on this line (without labelling)
\newcommand{\showlnlabel}[1]{\lnlset{#1}{\theAlgoLine}\ignorespaces} % display the line number and label this line
%
%%
%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Styling text commands
%
\newcommand{\AlTitleFnt}[1]{\textbf{#1}\unskip}% default definition
\newcommand{\SetAlTitleFnt}[1]{\renewcommand{\AlTitleFnt}[1]{\csname#1\endcsname{##1}\unskip}}%
\newcommand{\AlFnt}{\relax}% default definition
\newcommand{\SetAlFnt}[1]{\renewcommand{\AlFnt}{#1}}%
\newcommand{\AlCapFnt}{\AlFnt{}}% default definition
\newcommand{\SetAlCapFnt}[1]{\renewcommand{\AlCapFnt}{#1}}%
\newcommand{\KwSty}[1]{\textnormal{\textbf{#1}}\unskip}% default definition
\newcommand{\SetKwSty}[1]{\renewcommand{\KwSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
\newcommand{\ArgSty}[1]{\textnormal{\emph{#1}}\unskip}%\SetArgSty{emph}
\newcommand{\SetArgSty}[1]{\renewcommand{\ArgSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
\newcommand{\FuncSty}[1]{\textnormal{\texttt{#1}}\unskip}%\SetFuncSty{texttt}
\newcommand{\SetFuncSty}[1]{\renewcommand{\FuncSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
\newcommand{\DataSty}[1]{\textnormal{\textsf{#1}}\unskip}%%\SetDataSty{textsf}
\newcommand{\SetDataSty}[1]{\renewcommand{\DataSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
\newcommand{\CommentSty}[1]{\textnormal{\texttt{#1}}\unskip}%%\SetDataSty{texttt}
\newcommand{\SetCommentSty}[1]{\renewcommand{\CommentSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
\newcommand{\TitleSty}[1]{#1\unskip}%\SetTitleSty{}{}
\newcommand{\SetTitleSty}[2]{\renewcommand{\TitleSty}[1]{%
\csname#1\endcsname{\csname#2\endcsname##1}}\unskip}
%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Block basic commands
%
\newcommand{\al@push}[1]{\advance\skiptotal by #1\moveright #1}
\newcommand{\al@pop}[1]{\advance\skiptotal by -#1}
\newcommand{\al@addskiptotal}{\advance\skiptotal by 0.4pt\advance\hsize by -0.4pt}  % 0.4 pt=width of \vrule
\newcommand{\al@subskiptotal}{\advance\skiptotal by -0.4pt\advance\hsize by 0.4pt} % 0.4 pt=width of \vrule
%
\skiphlne=.8ex%
\newcommand{\Setvlineskip}[1]{\skiphlne=#1}
\newcommand{\V@line}[1]{%     no vskip in between boxes but a strut to separate them, 
  \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
  \al@push{\skiprule}%        move to the right before the vertical rule
  \hbox{\vrule%
    \vtop{\al@push{\skiptext}%move the right after the rule
      \vtop{\al@addskiptotal\advance\hsize by -\skiplength #1}\Hlne}}\vskip\skiphlne% inside the block
  \al@pop{\skiprule}%\al@subskiptotal% restore indentation
  \nointerlineskip}% no vskip after
%
\newcommand{\V@sline}[1]{%    no vskip in between boxes but a strut to separate them, 
  \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
  \al@push{\skiprule}%        move to the right before the vertical rule
  \hbox{\vrule%               the vertical rule
    \vtop{\al@push{\skiptext}%move the right after the rule
      \vtop{\al@addskiptotal\advance\hsize by -\skiplength #1}}}% inside the block
  \al@pop{\skiprule}}% restore indentation
  %\nointerlineskip}%  no vskip after
%
\newcommand{\H@lne}{\hrule height 0.4pt depth 0pt width .5em}
%
\newcommand{\No@line}[1]{%    no vskip in between boxes but a strut to separate them, 
  \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
  \al@push{\skiprule}%
  \hbox{%
    \vtop{\al@push{\skiptext}%
      \vtop{\advance\hsize by -\skiplength #1}}}% inside the block
  \al@pop{\skiprule}}%
  %\nointerlineskip}% no vskip after
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% default=NoLine
%
\newcommand{\a@@block}[2]{\No@line{##1}\KwSty{##2}\par}
\newcommand{\a@block}[2]{\a@@block{#1}{#2}} % this to be redefined as a@group in
                                            % case of noend option
\newcommand{\a@group}[1]{\No@line{##1}}
\newcommand{\Hlne}{}
%
%
\newcommand{\SetNoline}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Noline
\renewcommand{\a@@block}[2]{\No@line{##1}\KwSty{##2}\strut\par}%
\renewcommand{\a@group}[1]{\No@line{##1}}
\renewcommand{\Hlne}{}}
%
\newcommand{\SetVline}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Vline
\renewcommand{\a@@block}[2]{\V@line{##1}}%
\renewcommand{\a@group}[1]{\V@sline{##1}\strut\ignorespaces}
\renewcommand{\Hlne}{\H@lne}}
%
\newcommand{\SetLine}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Line
\renewcommand{\a@@block}[2]{\strut\V@sline{##1}\KwSty{##2}\strut\par}% no skip after a block so garantie at least a line
\renewcommand{\a@group}[1]{\V@sline{##1}\strut\ignorespaces}
\renewcommand{\Hlne}{}}
%
\newcommand{\SetNothing}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Noline
\renewcommand{\a@@block}[2]{\No@line{##1}\par}%
%\long
\renewcommand{\a@group}[1]{\No@line{##1}}
\renewcommand{\Hlne}{}}
%
%%
%%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ``Input :'''s like command 
%
%%%
% text staying at the right of the longer keyword of KwInOut commands 
% (text of KwInOut commands are all vertically aligned)
%
\newcommand{\algocf@newinout}{\par\parindent=\wd\algocf@inoutbox}% to put right indentation after a \\ in the KwInOut
\newcommand{\SetKwInOut}[2]{%
  \sbox\algocf@inoutbox{\hbox{\KwSty{#2}\algocf@typo:\ }}%
  \expandafter\ifx\csname InOutSizeDefined\endcsname\relax% if first time used
    \newcommand\InOutSizeDefined{}\setlength{\inoutsize}{\wd\algocf@inoutbox}%
  \else% else keep the larger dimension
    \ifdim\wd\algocf@inoutbox>\inoutsize\setlength{\inoutsize}{\wd\algocf@inoutbox}\fi%
  \fi% the dimension of the box is now defined.
  \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
  \expandafter\algocf@mkcmd\csname#1\endcsname[1]{%
    \ifthenelse{\boolean{algocf@inoutnumbered}}{\relax}{\everypar={\relax}}
    {\let\\\algocf@newinout\hangindent=\wd\algocf@inoutbox\hangafter=1\parbox[t]{\inoutsize}{\KwSty{#2}\hfill:\mbox{\ }}##1\par}
    \algocf@linesnumbered% reset the numbering of the lines
  }}%
%
%% allow to ajust the skip size of InOut
%%
\newcommand{\ResetInOut}[1]{%
  \sbox\algocf@inoutbox{\hbox{\KwSty{#1}\algocf@typo:\ }}%
  \setlength{\inoutsize}{\wd\algocf@inoutbox}%
  }
%
% 
%%%
% text staying at the right of the keyword.
%
\newcommand{\algocf@newinput}{\par\parindent=\wd\algocf@inputbox}% to put right indentation after a \\ in the KwInput
\newcommand{\SetKwInput}[2]{%
  \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
  \expandafter\algocf@mkcmd\csname#1\endcsname[1]{%
    \sbox\algocf@inputbox{\hbox{\KwSty{#2}\algocf@typo: }}%
    \ifthenelse{\boolean{algocf@inoutnumbered}}{\relax}{\everypar={\relax}}%
    {\let\\\algocf@newinput\hangindent=\wd\algocf@inputbox\hangafter=1\unhbox\algocf@inputbox##1\par}%
    \algocf@linesnumbered% reset the numbering of the lines
  }}%
\newcommand{\SetKwData}[2]{%
  \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
  \expandafter\algocf@mkcmd\csname @#1\endcsname[1]{\DataSty{#2(}\ArgSty{##1}\DataSty{)}}%
  \expandafter\algocf@mkcmd\csname#1\endcsname{%
    \@ifnextchar\bgroup{\csname @#1\endcsname}{\DataSty{#2}\xspace}}%
  }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Comments macros
%
%%%%
% comment in the text, first argument is the name of the macro, second is
% the text put before the comment, third is the text put at the end of the
% comment.
%
% first side comment justification
\newcommand{\SetSideCommentLeft}{\setboolean{algocf@scleft}{true}}
\newcommand{\SetSideCommentRight}{\setboolean{algocf@scleft}{false}}
\newcommand{\SetNoFillComment}{\setboolean{algocf@optfillcomment}{false}}
\newcommand{\SetFillComment}{\setboolean{algocf@optfillcomment}{true}}
%
% next comment and side comment
%
\newcommand{\algocf@endmarkcomment}{\relax}%
\newcommand{\algocf@fillcomment}{%
  \ifthenelse{\boolean{algocf@optfillcomment}}{\hfill}{\relax}}%
%
\newcommand{\algocf@startcomment}{%
  \hangindent=\wd\algocf@inputbox\hangafter=1\usebox\algocf@inputbox}%
\newcommand{\algocf@endcomment}{\algocf@fillcomment\algocf@endmarkcomment\ignorespaces\par}%
\newcommand{\algocf@endstartcomment}{\algocf@endcomment\algocf@startcomment\ignorespaces}%
%
\newboolean{algocf@sidecomment}%
\newboolean{algocf@altsidecomment}\setboolean{algocf@altsidecomment}{false}%
\newcommand{\algocf@scpar}{\ifthenelse{\boolean{algocf@altsidecomment}}{\relax}{\par}}%
\newcommand{\algocf@sclfill}{\ifthenelse{\boolean{algocf@scleft}}{\algocf@fillcomment}{\relax}}%
\newcommand{\algocf@scrfill}{\ifthenelse{\boolean{algocf@scleft}}{\relax}{\hfill}}
\newcommand{\algocf@startsidecomment}{\usebox\algocf@inputbox}%
\newcommand{\algocf@endsidecomment}{\algocf@endmarkcomment\algocf@scpar}%
\newcommand{\algocf@endstartsidecomment}{%
  \algocf@sclfill\algocf@endsidecomment%
  \algocf@scrfill\algocf@startsidecomment\ignorespaces}%
%
\newcommand{\SetKwComment}[3]{%
  % newcommand or renewcommand ?
  \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
  %%% comment definition
  \expandafter\algocf@mkcmd\csname algocf@#1\endcsname[1]{%
    \sbox\algocf@inputbox{\CommentSty{\hbox{#2}}}%
    \ifthenelse{\boolean{algocf@commentsnumbered}}{\relax}{\everypar={\relax}}%
    {\renewcommand{\algocf@endmarkcomment}{#3}%
      \let\\\algocf@endstartcomment%
      \algocf@startcomment\CommentSty{%
        \strut\ignorespaces##1\strut\algocf@fillcomment#3}\par}%
    \algocf@linesnumbered% reset the numbering of the lines
  }%
  %%% side comment definitions
  % option or not?
  \expandafter\algocf@mkcmd\csname algocf@#1@star\endcsname{%
    \@ifnextchar [{\csname algocf@#1@staropt\endcsname}{\csname algocf@#1@sidecomment\endcsname}%
  }%
  % manage option
  \expandafter\def\csname algocf@#1@staropt\endcsname[##1]##2{%
    \ifthenelse{\boolean{algocf@scleft}}{\setboolean{algocf@sidecomment}{true}}{\setboolean{algocf@sidecomment}{false}}%
    \ifx##1h\setboolean{algocf@altsidecomment}{true}\SetSideCommentLeft\fi%
    \ifx##1f\setboolean{algocf@altsidecomment}{true}\SetSideCommentRight\fi%
    \ifx##1l\setboolean{algocf@altsidecomment}{false}\SetSideCommentLeft\fi%
    \ifx##1r\setboolean{algocf@altsidecomment}{false}\SetSideCommentRight\fi%
    \csname algocf@#1@sidecomment\endcsname{##2}% call sidecomment
    \ifthenelse{\boolean{algocf@sidecomment}}{\setboolean{algocf@scleft}{true}}{\setboolean{algocf@scleft}{false}}%
    \setboolean{algocf@altsidecomment}{false}%
  }%
  % side comment
  \expandafter\algocf@mkcmd\csname algocf@#1@sidecomment\endcsname[1]{%
    \sbox\algocf@inputbox{\CommentSty{\hbox{#2}}}%
    \ifthenelse{\boolean{algocf@commentsnumbered}}{\relax}{\everypar={\relax}}%
    {%
      \renewcommand{\algocf@endmarkcomment}{#3}%
      \let\\\algocf@endstartsidecomment%
      % here is the comment
      \ifthenelse{\boolean{algocf@altsidecomment}}{\relax}{\algocf@endline\ }%
      \algocf@scrfill\algocf@startsidecomment\CommentSty{%
        \strut\ignorespaces##1\strut\algocf@sclfill#3}\algocf@scpar%
    }%
    \algocf@linesnumbered% reset the numbering of the lines
  }
  \expandafter\algocf@mkcmd\csname#1\endcsname{\@ifstar{\csname algocf@#1@star\endcsname}{\csname algocf@#1\endcsname}}
}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Kw
%
\newcommand{\SetKw}[2]{%
  \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
  \expandafter\algocf@mkcmd\csname @#1\endcsname[1]{\KwSty{#2} \ArgSty{##1}}%
  \expandafter\algocf@mkcmd\csname#1\endcsname{%
    \@ifnextchar\bgroup{\csname @#1\endcsname}{\KwSty{#2}\xspace}}%
  }
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% KwFunction
%
\newcommand{\SetKwFunction}[2]{%
  \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
  \expandafter\algocf@mkcmd\csname @#1\endcsname[1]{\FuncSty{#2(}\ArgSty{##1}\FuncSty{)}}%
  \expandafter\algocf@mkcmd\csname#1\endcsname{%
    \@ifnextchar\bgroup{\csname @#1\endcsname}{\FuncSty{#2}\xspace}}%
}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% KwBlock
%
\newcommand{\SetKwBlock}[3]{%
\@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
% side text or not? 
\expandafter\def\csname#1\endcsname{ %Begin
  \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}
% with side text
\expandafter\def\csname algocf@#1opt\endcsname(##1)##2{% \Begin(){}
  \KwSty{#2} ##1\a@group{##2}\KwSty{#3}%
  \@ifnextchar({\csname algocf@#1end\endcsname}{\par}}%
% without side text at the beginning
\expandafter\algocf@mkcmd\csname algocf@#1\endcsname[1]{% \Begin{}
  \KwSty{#2}\a@group{##1}\KwSty{#3}\@ifnextchar({\csname algocf@#1end\endcsname}{\par}}%
% side text at the end
\expandafter\def\csname algocf@#1end\endcsname(##1){% \Begin{}
  \ ##1\par}%
}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% For Switch
%
\newcommand{\SetKwSwitch}[8]{% #1=\Switch #2=\Case #3=\Other #4=swicth #5=case #6=do #7=otherwise #8=endsw
%%%% Switch
\@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
% side text or not? 
\expandafter\def\csname#1\endcsname{ %Switch
  \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}
% with side text
\expandafter\def\csname algocf@#1opt\endcsname(##1)##2##3{% \Switch(){}{}
  \KwSty{#4} \ArgSty{##2} \KwSty{#5} ##1\a@block{##3}{#8}}%
% without side text
\expandafter\algocf@mkcmd\csname algocf@#1\endcsname[2]{% \Switch{}{}
  \KwSty{#4} \ArgSty{##1} \KwSty{#5}\a@block{##2}{#8}}%
% side text at the end
\expandafter\def\csname algocf@#1end\endcsname(##1){% \Switch{}{}()
  
}

%%%% Case
\@ifundefined{algocf@#2}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
% side text or not?
\expandafter\def\csname#2\endcsname{ %Case
  \@ifnextchar({\csname algocf@#2opt\endcsname}{\csname algocf@#2\endcsname}}
\expandafter\def\csname u#2\endcsname{ %uCase
  \@ifnextchar({\csname algocf@u#2opt\endcsname}{\csname algocf@u#2\endcsname}}
\expandafter\def\csname l#2\endcsname{ %lCase
  \@ifnextchar({\csname algocf@l#2opt\endcsname}{\csname algocf@l#2\endcsname}}
% with side text
\expandafter\def\csname algocf@#2opt\endcsname(##1)##2##3{% \Case(){}{}
  \KwSty{#6} \ArgSty{##2} ##1\a@block{##3}{#8}}%
\expandafter\def\csname algocf@u#2opt\endcsname(##1)##2##3{% \uCase(){}{}
  \KwSty{#6} \ArgSty{##2} ##1\a@group{##3}}%
\expandafter\def\csname algocf@l#2opt\endcsname(##1)##2##3{% \lCase(){}{}
  \KwSty{#6} \ArgSty{##2} ##3\algocf@endline\ ##1\par}%
% without side text
\expandafter\algocf@mkcmd\csname algocf@#2\endcsname[2]{% \Case{}{}
  \KwSty{#6} \ArgSty{##1}\a@block{##2}{#8}}%
\expandafter\algocf@mkcmd\csname algocf@u#2\endcsname[2]{% \uCase{}{}
  \KwSty{#6} \ArgSty{##1}\a@group{##2}}%
\expandafter\algocf@mkcmd\csname algocf@l#2\endcsname[2]{% \lCase{}{}
  \KwSty{#6} \ArgSty{##1} ##2}%
%%%% Other
\@ifundefined{algocf@#3}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
% side text or not? 
\expandafter\def\csname#3\endcsname{ %Other
  \@ifnextchar({\csname algocf@#3opt\endcsname}{\csname algocf@#3\endcsname}}
\expandafter\def\csname l#3\endcsname{ %Other
  \@ifnextchar({\csname algocf@l#3opt\endcsname}{\csname algocf@l#3\endcsname}}
% with side text
\expandafter\def\csname algocf@#3opt\endcsname(##1)##2{% \Other(){}{}
  \KwSty{#7} ##1\a@block{##2}{#8}}%
\expandafter\def\csname algocf@l#3opt\endcsname(##1)##2{% \Other(){}{}
  \KwSty{#7} ##2\algocf@endline\ ##1\par}%
% without side text
\expandafter\algocf@mkcmd\csname algocf@#3\endcsname[1]{% default
  \KwSty{#7}\a@block{##1}{#8}}% 
\expandafter\algocf@mkcmd\csname algocf@l#3\endcsname[1]{% ldefault
  \KwSty{#7} ##1}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% If macros
%
\newcommand{\SetKwIF}[8]{% #1=\If #2=\ElseIf #3=\Else #4=if #5=then #6=elseif si #7=else #8=endif
% 
% common text
\@ifundefined{#1@ifthen}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
\expandafter\algocf@mkcmd\csname #1@ifthen\endcsname[1]{%
  \KwSty{#4} \ArgSty{##1} \KwSty{#5}}%
\expandafter\algocf@mkcmd\csname #1@endif\endcsname[1]{\a@block{##1}{#8}}%
\expandafter\algocf@mkcmd\csname #1@noend\endcsname[1]{\a@group{##1}}%
\expandafter\algocf@mkcmd\csname #1@else\endcsname[1]{\a@group{##1}\KwSty{#7}}%
\@ifundefined{#2@elseif}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
\expandafter\algocf@mkcmd\csname #2@elseif\endcsname[1]{%
  \KwSty{#6} \ArgSty{##1} \KwSty{#5}}%
\@ifundefined{#3@else}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
\expandafter\algocf@mkcmd\csname #3@else\endcsname{\KwSty{#7}}%
%%%% If then { } endif
%
\@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
% side text or not?
\expandafter\def\csname#1\endcsname{%
  \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}
% with side text
\expandafter\def\csname algocf@#1opt\endcsname(##1)##2##3{% \If(){}{}
  \csname #1@ifthen\endcsname{##2} ##1\csname #1@endif\endcsname{##3}}%
% without side text
\expandafter\algocf@mkcmd\csname algocf@#1\endcsname[2]{% \If{}{}
  \csname #1@ifthen\endcsname{##1}\csname #1@endif\endcsname{##2}}%
%
%%%% If then {} else {} endif
%
% side text or not?
\expandafter\def\csname e#1\endcsname{%
  \@ifnextchar({\csname algocf@e#1opt\endcsname}{\csname algocf@e#1optif\endcsname}}
% with side text after if
\expandafter\def\csname algocf@e#1opt\endcsname(##1)##2##3{% \eIf()
  \csname #1@ifthen\endcsname{##2} ##1\csname #1@else\endcsname{##3}%
  \csname algocf@e#1opte\endcsname}
% without side text after if
\expandafter\def\csname algocf@e#1optif\endcsname##1##2{% \eIf()
  \csname #1@ifthen\endcsname{##1}\csname #1@else\endcsname{##2}%
  \csname algocf@e#1opte\endcsname}%
% side text after else or not ?
\expandafter\def\csname algocf@e#1opte\endcsname{% 
  \@ifnextchar({\csname algocf@e#1optopt\endcsname}{\csname algocf@e#1\endcsname}}
% else with a side text
\expandafter\def\csname algocf@e#1optopt\endcsname(##1)##2{% 
  ##1\csname #1@endif\endcsname{##2}}
% else without side text
\expandafter\algocf@mkcmd\csname algocf@e#1\endcsname[1]{% 
  \csname #1@endif\endcsname{##1}}
%
%%%% If then 
%
% side text or not?
\expandafter\def\csname l#1\endcsname{% lif
  \@ifnextchar({\csname algocf@l#1opt\endcsname}{\csname algocf@l#1\endcsname}}
\expandafter\def\csname u#1\endcsname{% uif
  \@ifnextchar({\csname algocf@u#1opt\endcsname}{\csname algocf@u#1\endcsname}}
% with side text
\expandafter\def\csname algocf@l#1opt\endcsname(##1)##2##3{% \lIf(){}{}
  \csname #1@ifthen\endcsname{##2} ##3\algocf@endline\ ##1\par}%
\expandafter\def\csname algocf@u#1opt\endcsname(##1)##2##3{% \uIf(){}{}
  \csname #1@ifthen\endcsname{##2} ##1\csname#1@noend\endcsname{##3}}%
% without side text
\expandafter\algocf@mkcmd\csname algocf@l#1\endcsname[2]{% \lIf{}{}
  \csname #1@ifthen\endcsname{##1} ##2}%
\expandafter\algocf@mkcmd\csname algocf@u#1\endcsname[2]{% \uIf{}{}
  \csname #1@ifthen\endcsname{##1}\csname#1@noend\endcsname{##2}}%
%
%%%% ElseIf {} endif
%
\@ifundefined{algocf@#2}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
% side text or not?
\expandafter\def\csname#2\endcsname{% ElseIf
  \@ifnextchar({\csname algocf@#2opt\endcsname}{\csname algocf@#2\endcsname}}
% with side text
\expandafter\def\csname algocf@#2opt\endcsname(##1)##2##3{% \ElseIf(){}{}
  \csname #2@elseif\endcsname{##2} ##1\csname #1@endif\endcsname{##3}}
% without side text
\expandafter\algocf@mkcmd\csname algocf@#2\endcsname[2]{% \ElseIf{}{}
  \csname #2@elseif\endcsname{##1}\csname #1@endif\endcsname{##2}}
%
%%%% ElseIf
%
% side text or not?
\expandafter\def\csname l#2\endcsname{% lElseIf
  \@ifnextchar({\csname algocf@l#2opt\endcsname}{\csname algocf@l#2\endcsname}}
\expandafter\def\csname u#2\endcsname{% uElseIf
  \@ifnextchar({\csname algocf@u#2opt\endcsname}{\csname algocf@u#2\endcsname}}
% with side text
\expandafter\def\csname algocf@l#2opt\endcsname(##1)##2##3{% \lElseIf(){}{}
  \csname #2@elseif\endcsname{##2} ##3\algocf@endline\ ##1\par}
\expandafter\def\csname algocf@u#2opt\endcsname(##1)##2##3{% \uElseIf(){}{}
  \csname #2@elseif\endcsname{##2} ##1\csname #1@noend\endcsname{##3}}
% without side text
\expandafter\algocf@mkcmd\csname algocf@l#2\endcsname[2]{% \lElseIf{}{}
  \csname #2@elseif\endcsname{##1} ##2}%
\expandafter\algocf@mkcmd\csname algocf@u#2\endcsname[2]{% \uElseIf{}{}
  \csname #2@elseif\endcsname{##1}\csname #1@noend\endcsname{##2}}
%
%%%% Else {} endif
%
\@ifundefined{algocf@#3}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
% side text or not?
\expandafter\def\csname#3\endcsname{% Else
  \@ifnextchar({\csname algocf@#3opt\endcsname}{\csname algocf@#3\endcsname}}
% with side text
\expandafter\def\csname algocf@#3opt\endcsname(##1)##2{% \Else(){}
  \csname #3@else\endcsname\ ##1\csname #1@endif\endcsname{##2}}
% without side text
\expandafter\algocf@mkcmd\csname algocf@#3\endcsname[1]{% \Else{}
  \csname #3@else\endcsname\csname #1@endif\endcsname{##1}}%
%
%%%% Else 
%
% side text or not?
\expandafter\def\csname l#3\endcsname{% lElse
  \@ifnextchar({\csname algocf@l#3opt\endcsname}{\csname algocf@l#3\endcsname}}
\expandafter\def\csname u#3\endcsname{% uElse
  \@ifnextchar({\csname algocf@u#3opt\endcsname}{\csname algocf@u#3\endcsname}}
% with side text
\expandafter\def\csname algocf@l#3opt\endcsname(##1)##2{% \lElse(){}
  \csname #3@else\endcsname\ ##2\algocf@endline\ ##1\par}
\expandafter\def\csname algocf@#3opt\endcsname(##1)##2{% \uElse(){}
  \csname #3@else\endcsname\ ##1\csname #1@noend\endcsname{##2}}
% without side text
\expandafter\algocf@mkcmd\csname algocf@l#3\endcsname[1]{% \lElse{}
  \csname #3@else\endcsname\ ##1}%
\expandafter\algocf@mkcmd\csname algocf@u#3\endcsname[1]{% \uElse{}
  \csname #3@else\endcsname\csname #1@noend\endcsname{##1}}%
}
%
% old for backward compatibility
\newcommand{\SetKwIf}[6]{%
  \SetKwIF{#1}{cf@dumb}{#2}{#3}{#4}{cf@dumb}{#5}{#6}%
  \typeout{**** WARNING: SetKwIf deprecated: use SetKwIF instead*****^^J}%
}%
\newcommand{\SetKwIfElseIf}[8]{%
  \SetKwIF{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}%
  \typeout{**** WARNING: SetKwIfElseIf deprecated: use SetKwIF instead*****^^J}%
}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% For macros
%
\newcommand{\SetKwFor}[4]{%
\@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
% side text or not? 
\expandafter\def\csname#1\endcsname{ %For
  \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}
\expandafter\def\csname l#1\endcsname{ %For
  \@ifnextchar({\csname algocf@l#1opt\endcsname}{\csname algocf@l#1\endcsname}}
% with side text
\expandafter\def\csname algocf@#1opt\endcsname(##1)##2##3{% \For(){}{}
  \KwSty{#2} \ArgSty{##2} \KwSty{#3} ##1\a@block{##3}{#4}}%
\expandafter\def\csname algocf@l#1opt\endcsname(##1)##2##3{% \lFor(){}{}
  \KwSty{#2} \ArgSty{##2} \KwSty{#3} ##3\algocf@endline\ ##1\par}
% without side text
\expandafter\algocf@mkcmd\csname algocf@#1\endcsname[2]{% \For{}{}
  \KwSty{#2} \ArgSty{##1} \KwSty{#3}\a@block{##2}{#4}}%
\expandafter\algocf@mkcmd\csname algocf@l#1\endcsname[2]{% \lFor{}{}
  \KwSty{#2} \ArgSty{##1} \KwSty{#3} ##2}%
}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Repeat macros
%
\newcommand{\SetKwRepeat}[3]{%
\@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
% side text or not? 
\expandafter\def\csname#1\endcsname{ %Repeat
  \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}
\expandafter\def\csname l#1\endcsname{ %lRepeat
  \@ifnextchar({\csname algocf@l#1opt\endcsname}{\csname algocf@l#1\endcsname}}
% with side text
\expandafter\def\csname algocf@#1opt\endcsname(##1)##2##3{% \Repeat(){}{}
  \KwSty{#2} ##1\a@group{##3}\KwSty{#3} \ArgSty{##2}%
  \@ifnextchar({\csname algocf@#1optopt\endcsname}{\@endalgoln}%
}%
\expandafter\def\csname algocf@#1optopt\endcsname(##1){% \Repeat(){}{}()
  ##1\@endalgoln}%
\expandafter\def\csname algocf@l#1opt\endcsname(##1)##2##3{% \lRepeat(){}{}
  \KwSty{#2} ##3 \KwSty{#3} \ArgSty{##2}\algocf@endline\ ##1\par}%
% without side text
\expandafter\algocf@mkcmd\csname algocf@#1\endcsname[2]{% \Repeat{}{}
  \KwSty{#2}\a@group{##2}\KwSty{#3} \ArgSty{##1}
  \@ifnextchar({\csname algocf@#1optopt\endcsname}{\@endalgoln}%
}%
\expandafter\algocf@mkcmd\csname algocf@l#1\endcsname[2]{% \lRepeat{}{}
  \KwSty{#2} ##2 \KwSty{#3} \ArgSty{##1}}%
}
%
% 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%        Environments definitions     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%
%% Caption management
%%
% for the following macros:
% #1 is given by caption and is equal to fnum@algocf
% #2 is the text given in argument by the user in the \caption macro
%
%%%%% text of caption
\newcommand{\algocf@captiontext}[2]{#1\algocf@typo: \AlCapFnt{}#2} % text of caption
%
%%%%% default caption of algorithm: used if no specific style caption is defined
\newcommand{\algocf@makecaption}[2]{%
  \addtolength{\hsize}{\algomargin}%
  \sbox\@tempboxa{\algocf@captiontext{#1}{#2}}%
  \ifdim\wd\@tempboxa >\hsize%     % if caption is longer than a line
    \hskip .5\algomargin%
    \parbox[t]{\hsize}{\algocf@captiontext{#1}{#2}}% then caption is not centered
  \else%
    \global\@minipagefalse%
    \hbox to\hsize{\hfil\box\@tempboxa\hfil}% else caption is centered
  \fi%
  \addtolength{\hsize}{-\algomargin}%
}
%
\newsavebox\algocf@capbox
\newcommand{\algocf@makecaption@plain}[2]{%
  \global\sbox\algocf@capbox{\algocf@makecaption{#1}{#2}}}%
\newcommand{\algocf@makecaption@boxed}[2]{%
  \addtolength{\hsize}{-\algomargin}%
  \global\sbox\algocf@capbox{\algocf@makecaption{#1}{#2}}
  \addtolength{\hsize}{\algomargin}%
 }%
%
\newcommand{\algocf@makecaption@algoruled}[2]{\algocf@makecaption@ruled{#1}{#2}}%
\newcommand{\algocf@makecaption@boxruled}[2]{\algocf@makecaption@ruled{#1}{#2}}%
\newcommand{\algocf@makecaption@ruled}[2]{%
  \global\sbox\algocf@capbox{\hskip\AlCapHSkip% .5\algomargin%
    \parbox[t]{\hsize}{\algocf@captiontext{#1}{#2}}}% then caption is not centered
}
%
\newcommand{\algocf@caption@plain}{\vskip\AlCapSkip\box\algocf@capbox}%
\newcommand{\algocf@caption@boxed}{\vskip\AlCapSkip\box\algocf@capbox}%
\newcommand{\algocf@caption@ruled}{\box\algocf@capbox\kern2pt\hrule height.8pt depth0pt\kern2pt}%
\newcommand{\algocf@caption@algoruled}{\algocf@caption@ruled}%
\newcommand{\algocf@caption@boxruled}{%
  \addtolength{\hsize}{-0.8pt}%
  \hbox to\hsize{%
    \vrule%\hskip-0.35pt%
    \vbox{%
      \hrule\vskip2\lineskip%
      \hbox to\hsize{\unhbox\algocf@capbox\hfill}\vskip2\lineskip%
    }% 
    %\hskip-0.35pt%
    \vrule%
  }\vskip-2\lineskip\nointerlineskip%
  \addtolength{\hsize}{0.8pt}%
}
%
%
%%%% set caption for the environment

% beamer define is own caption overrinding latex caption!
% as we need it, we have put here the original definition
\long\def\algocf@latexcaption#1[#2]#3{% original definition of caption
  \par
  \addcontentsline{\csname ext@#1\endcsname}{#1}%
  {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
  \begingroup
  \@parboxrestore
  \if@minipage
    \@setminipage
  \fi
  \normalsize
  \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup%
}

\ifx\beamer@makecaption\undefined%
\else% beamer detected
\ifx\@makecaption\undefined%
\newcommand{\@makecaption}[2]{\relax}%
\fi%
\fi

%
% more and more packages redefine \@caption instead of just \@makecaption which makes algorithm2e
% caption not works since based on standard \@caption. So we force the definition of \@caption to be
% the standard one (the one from LaTeX) inside algorithm environment.
%
\newcommand{\algocf@setcaption}{%
  \let\algocf@savecaption=\@caption%
  \let\@caption=\algocf@latexcaption%
  \let\algocf@oldmakecaption=\@makecaption%
  \renewcommand{\@makecaption}[2]{%
    \expandafter\csname algocf@makecaption@\algocf@style\endcsname{##1}{##2}}%
}
%
%%%%% reset caption
%
% since we have force the LaTeX caption for algorithm environment, we must go back to the caption
% used in the text.
\newcommand{\algocf@resetcaption}{%
  \let\@caption=\algocf@savecaption%
  \let\@makecaption=\algocf@oldmakecaption%
}
%
%%%%% nocaptionofalgo and restorecaptionofalgo --
\newcommand{\nocaptionofalgo}{%
  \let\@old@algocf@captiontext=\algocf@captiontext%
  \renewcommand{\algocf@captiontext}[2]{\AlCapFnt{}##2}%
}
\newcommand{\restorecaptionofalgo}{%
  \let\algocf@captiontext=\@old@algocf@captiontext%
}
%
% ----------------------  algocf environment
%
\newcounter{algocfline}                    % new counter to make lines numbers be internally 
\setcounter{algocfline}{0}                 % different in different algorithms
%
\expandafter\ifx\csname algocf@within\endcsname\relax% if \algocf@within doesn't exist
\newcounter{algocf}                        % just define a new counter
\renewcommand\thealgocf{\@arabic\c@algocf} % and the way it is printed
\else%                                    else
\newcounter{algocf}[\algocf@within]        % counter is numbered within \algocf@within
\renewcommand\thealgocf{\csname the\algocf@within\endcsname.\@arabic\c@algocf}
\fi
%
\def\fps@algocf{htbp}         % default
\def\ftype@algocf{10}         % float type
\def\ext@algocf{\algocf@list} % loa by default, lof if figure option used
\def\fnum@algocf{{\AlCapFnt\AlTitleFnt{\algorithmcfname\nobreakspace\thealgocf}}}
\newenvironment{algocf}%      % float environment for algorithms
               {\@float{algocf}}%
               {\end@float}
\newenvironment{algocf*}%     % float* environment for algorithms
               {\@dblfloat{algocf}}
               {\end@dblfloat}

\ifx\l@chapter\undefined%
\newcommand\listofalgocfs{    % list of algorithms
    \section*{\listalgorithmcfname}%
      \@mkboth{\MakeUppercase\listalgorithmcfname}%
              {\MakeUppercase\listalgorithmcfname}%
    \@starttoc{loa}%
    }
\else%
%\newcommand\listofalgocfs{%
%    \if@twocolumn
%      \@restonecoltrue\onecolumn
%    \else
%      \@restonecolfalse
%    \fi
%    \chapter*{\listalgorithmcfname}%
%      \@mkboth{\MakeUppercase\listalgorithmcfname}%
%              {\MakeUppercase\listalgorithmcfname}%
%    \@starttoc{loa}%
%    \if@restonecol\twocolumn\fi
%    }
\fi


\newcommand*\l@algocf{\@dottedtocline{1}{1em}{2.3em}}% line of the list
%
% ----------------------  algorithm environment
%
%%%%%%%
%%
%% Algorithm environment definition
%%
%%%%%%%
%%
%
\newsavebox\algocf@algoframe
\def\@algocf@pre@plain{\relax}%  action to be done before printing the algo.
\def\@algocf@post@plain{\relax}% action to be done after printing the algo.
\def\@algocf@capt@plain{bottom}% where the caption should be localized.
\def\@algocf@pre@boxed{\noindent\begin{lrbox}{\algocf@algoframe}}
\def\@algocf@post@boxed{\end{lrbox}\framebox[\hsize]{\box\algocf@algoframe}\par}%
\def\@algocf@capt@boxed{under}%
\def\@algocf@pre@ruled{\hrule height.8pt depth0pt\kern2pt}%
\def\@algocf@post@ruled{\kern2pt\hrule\relax}%
\def\@algocf@capt@ruled{top}%
\def\@algocf@pre@algoruled{\hrule height.8pt depth0pt\kern2pt}%
\def\@algocf@post@algoruled{\kern2pt\hrule\relax}%
\def\@algocf@capt@algoruled{top}%
\def\@algocf@pre@boxruled{\noindent\begin{lrbox}{\algocf@algoframe}}%
\def\@algocf@post@boxruled{\end{lrbox}\framebox[\hsize]{\box\algocf@algoframe}\par}%
\def\@algocf@capt@boxruled{above}%
%
%% before algocf or figure environment
\newcommand{\@algocf@init@caption}{%
  \@algocf@algotitleofalgo% fix name for \Titleofalgo to \algorithmcfname
  \algocf@setcaption%       set caption to our caption style
}%
\newcommand{\@algocf@init}{%
  \refstepcounter{algocfline}%
  \ifthenelse{\boolean{algocf@optnoend}}{%
      \renewcommand{\a@block}[2]{\a@group{##1}}%
    }{%
      \renewcommand{\a@block}[2]{\a@@block{##1}{##2}}%
    }%
}
%% after the end of algocf or figure environment
\newcommand{\@algocf@term@caption}{%
  \algocf@resetcaption% restore original caption
}%
\newcommand{\@algocf@term}{%
  \setboolean{algocf@algoH}{false}% no H by default
  \ifthenelse{\boolean{algocf@optnoend}}{%
      \renewcommand{\a@block}[2]{\a@@block{##1}{##2}}
    }{%
      \renewcommand{\a@block}[2]{\a@group{##1}}%
    }%
}
%
%%%%%%%%%%%%%%%%%
%% makethealgo: macro which print effectively the algo in its box
%% 
\newsavebox\algocf@algobox
\newcommand{\algocf@makethealgo}{%
  \vtop{%
    % place caption above if needed  bye the style
    \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{above}}%
    {\csname algocf@caption@\algocf@style\endcsname}{}%
    %
    % precommand according to the style
    \csname @algocf@pre@\algocf@style\endcsname%
    % place caption at top if needed  bye the style
     \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{top}}%
     {\csname algocf@caption@\algocf@style\endcsname}{}%
    %
    \box\algocf@algobox% the algo
    % place caption at bottom if needed  bye the style
     \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{bottom}}%
     {\csname algocf@caption@\algocf@style\endcsname}{}%
    % postcommand according to the style
    \csname @algocf@post@\algocf@style\endcsname%
    % place caption under if needed  bye the style
     \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{under}}
     {\csname algocf@caption@\algocf@style\endcsname}{}%
  }%
}
%%%%%%%%%%%%%%%%%%%
%
%% at the beginning of algocf or figure environment
\newcommand{\@algocf@start}{%
  \@algoskip%
  \begin{lrbox}{\algocf@algobox}%
  \setlength{\algowidth}{\hsize}%
  \vbox\bgroup% save all the algo in a box
  \hbox to\algowidth\bgroup\hbox to \algomargin{\hfill}\vtop\bgroup%
  \ifthenelse{\boolean{algocf@slide}}{\parskip 0.5ex\color{black}}{}%
  % initialization
  \addtolength{\hsize}{-1.5\algomargin}%
  \let\@mathsemicolon=\;\def\;{\ifmmode\@mathsemicolon\else\@endalgoln\fi}%
  \raggedright\AlFnt{}%
  \ifthenelse{\boolean{algocf@slide}}{\incmargin{\skipalgocfslide}}{}%
  \@algoinsideskip%
  %
}
%
%% at the end of algocf or figure environment
\newcommand{\@algocf@finish}{%
  \@algoinsideskip%
  \egroup%end of vtop which contain all the text
  \egroup%end of hbox wich contains [margin][vtop]
  \ifthenelse{\boolean{algocf@slide}}{\decmargin{\skipalgocfslide}}{}%
  %
  \egroup%end of main vbox
  \end{lrbox}%
  %\egroup% end of algo box
  \algocf@makethealgo% print the algo
  \@algoskip%
  % restore dimension and macros
  \setlength{\hsize}{\algowidth}%
  \lineskip\normallineskip\setlength{\skiptotal}{\@defaultskiptotal}%
  \let\;=\@mathsemicolon%  
  %
}
%%%%%%%%%%%%%%%%%%%%
%% basic definition of the environment algorithm
%%

\newboolean{algocf@algoH}\setboolean{algocf@algoH}{false}
\newenvironment{algocf@Here}{\noindent%
  \def\@captype{algocf}% if not defined, caption exit with an error
%  \hbox\bgroup%
  \begin{minipage}{\hsize}
}{%
  \end{minipage}
%  \egroup%
}%
\newenvironment{\algocf@envname}[1][htbp]{%
   \@algocf@init%
   \ifthenelse{\equal{\algocf@float}{figure}}%
     {\begin{figure}[#1]}%
   {\@algocf@init@caption\ifthenelse{\equal{#1}{H}}%
     {\setboolean{algocf@algoH}{true}\begin{algocf@Here}}%
     {\begin{algocf}[#1]}%
   }%
    \@algocf@start% 
    \@ResetCounterIfNeeded%
    \algocf@linesnumbered%
}{%
    \@algocf@finish%
    \ifthenelse{\equal{\algocf@float}{figure}}%
     {\end{figure}}%
   {\@algocf@term@caption\ifthenelse{\boolean{algocf@algoH}}%
     {\end{algocf@Here}}%
     {\end{algocf}}%
   }%
   \@algocf@term
}
%%%
%%% algorithm*
%%%
\newenvironment{\algocf@envname*}[1][htbp]{%
  \@algocf@init%
  \ifthenelse{\equal{\algocf@float}{figure}}%
    {\begin{figure*}[#1]}%
    {\begin{algocf*}[#1]}%
     \@algocf@start%
     \@ResetCounterIfNeeded%
     \algocf@linesnumbered%
}{
     \@algocf@finish%
  \ifthenelse{\equal{\algocf@float}{figure}}%
  {\end{figure*}}%
  {\end{algocf*}}%
  \@algocf@term%
}
%
%%%%%%%%%%%%%%%%%%%%%%%
%%%
%
\expandafter\newcommand\csname\algocf@listofalgorithms\endcsname{%
  \ifthenelse{\equal{\algocf@float}{figure}}{\listoffigures}{\listofalgocfs}
}
%%%
%%%
%
% ----------------------  procedure and function environments
%
%
% -- new style (used in particular in the caption of function and procedure environments)
%
\newcommand{\ProcNameSty}[1]{\FuncSty{#1}}%
\newcommand{\SetProcNameSty}[1]{\renewcommand{\ProcNameSty}[1]{\textnormal{\csname#1\endcsname{##1}}}}
\newcommand{\ProcArgSty}[1]{\ArgSty{#1}}%
\newcommand{\SetProcArgSty}[1]{\renewcommand{\ProcArgSty}[1]{\textnormal{\csname#1\endcsname{##1}}}}
% three macros to extract parts of the caption
\gdef\algocf@captname#1(#2)#3@{#1}  % keep characters before the first brace
\gdef\algocf@captparam#1(#2)#3@{#2} % keep character in between the braces
\gdef\algocf@captother#1(#2)#3@{#3} % keep character after the braces
%
%%% Text of caption for Procedure or Function
\newcommand{\algocf@captionproctext}[2]{%
  {\AlCapFnt{}\AlTitleFnt{\algocf@procname} %
  \ProcNameSty{\algocf@captname #2@}% Name of the procedure in ProcName Style. 
  \ifthenelse{\equal{\algocf@captparam #2@}{\arg@e}}{}% if no argument, write nothing
  {%                                                else put arguments in ProcArgSty:
    \ProcNameSty{(}\ProcArgSty{\algocf@captparam #2@}\ProcNameSty{)}%
  }% endif
  \algocf@captother #2@%
  }
}
%%%% set caption for the environment
% unfortunately, makecaption is called with \ignorespace #3 so 
% we can't do the @currentlabel definition inside \algocf@captionproctext
\long\def\algocf@caption@proc#1[#2]#3{% 
  \gdef\@currentlabel{\algocf@captname #3@}%
  \algocf@old@caption{#1}[\algocf@procname\nobreakspace #2]{\ #3}%
}%
\newcommand{\algocf@setcaptionproc}{%
  \let\algocf@oldcaptiontext=\algocf@captiontext%
  \renewcommand{\algocf@captiontext}[2]{%
    \algocf@captionproctext{##1}{##2}}%
  \let\algocf@old@caption=\@caption%
  \let\@caption=\algocf@caption@proc%
}
%%%%% reset caption
\newcommand{\algocf@resetcaptionproc}{%
  \let\algocf@captiontext=\algocf@oldcaptiontext%
  \let\@caption=\algocf@old@caption%
}
%
%
%%%%% algocf@proc is the generic environment for procedure and function environment.
%
\newboolean{algocf@procstar}\setboolean{algocf@procstar}{false}
\newenvironment{algocf@proc}[1][htbp]{%
    \@algocf@proctitleofalgo% set Titleofalgo to Procedure: or Function:
                            % accordingly to the environment
    \let\old@thealgocf=\thealgocf%\renewcommand{\thealgocf}{--}%
    \algocf@setcaptionproc%   set the text of caption to proc
    \algocf@setcaption%       set caption to our caption style
    \refstepcounter{algocfline}%
    \ifthenelse{\equal{\algocf@float}{figure}}{%
      \ifthenelse{\boolean{algocf@procstar}}{\begin{figure*}[#1]}{\begin{figure}[#1]}%
    }{%
      \ifthenelse{\boolean{algocf@procstar}}%
         {\begin{algocf*}[#1]}%
         {\ifthenelse{\equal{#1}{H}}%
            {\setboolean{algocf@algoH}{true}\begin{algocf@Here}}%
            {\begin{algocf}[#1]}%
         }%
    }%
       \@algocf@start%
       \@ResetCounterIfNeeded%
       \algocf@linesnumbered%
}{%
       \@algocf@finish%
    \ifthenelse{\equal{\algocf@float}{figure}}{%
      \ifthenelse{\boolean{algocf@procstar}}{\end{figure*}}{\end{figure}}%
    }{%
      \ifthenelse{\boolean{algocf@procstar}}
         {\end{algocf*}}
         {\ifthenelse{\boolean{algocf@algoH}}
            {\end{algocf@Here}}%
            {\end{algocf}}%
         }%
    }%
    \let\thealgocf=\old@thealgocf%
    \@algocf@term% restore original caption and H boolean
    \algocf@resetcaptionproc%
}

%
% -- procedure and function environments are defined from algocf@proc environment
%
\newenvironment{procedure}[1][htbp]%
{\setboolean{algocf@procstar}{false}%
 \newcommand{\algocf@procname}{\@algocf@procname}\begin{algocf@proc}[#1]}%
{\end{algocf@proc}}
\newenvironment{function}[1][htbp]%
{\setboolean{algocf@procstar}{false}%
 \newcommand{\algocf@procname}{\@algocf@funcname}\begin{algocf@proc}[#1]}%
{\end{algocf@proc}}
%
\newenvironment{procedure*}[1][htbp]%
{\setboolean{algocf@procstar}{true}%
 \newcommand{\algocf@procname}{\@algocf@procname}\begin{algocf@proc}[#1]}%
{\end{algocf@proc}}
\newenvironment{function*}[1][htbp]%
{\setboolean{algocf@procstar}{true}%
 \newcommand{\algocf@procname}{\@algocf@funcname}\begin{algocf@proc}[#1]}%
{\end{algocf@proc}}
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 
\newcommand{\Titleofalgo}[1]{\@titleprefix\TitleSty{#1}\par\smallskip}
%
%
% -------------------------   Default Definitions
%
%%
%%
%
\newcommand{\algocf@defaults@common}{
%\SetKwInOut{AlgDonnees}{Donn\'ees}\SetKwInOut{AlgRes}{R\'esultat}
\SetKwInput{Donnees}{Donn\'ees}%
\SetKwInput{Res}{R\'esultat}%
\SetKwInput{Entree}{Entr\'ees}%
\SetKwInput{Sortie}{Sorties}%
\SetKw{KwA}{\`a}%
\SetKw{Retour}{retourner}%
\SetKwBlock{Deb}{d\'ebut}{fin}%
\SetKwRepeat{Repeter}{r\'ep\'eter}{jusqu'\`a}%
%
\SetKwComment{tcc}{/* }{ */}
\SetKwComment{tcp}{// }{}
%
%\SetKwInOut{AlgData}{Data}\SetKwInOut{AlgResult}{Result}
\SetKwInput{KwIn}{Input}%
\SetKwInput{KwOut}{Output}%
\SetKwInput{KwData}{Data}%
\SetKwInput{KwResult}{Result}%
\SetKw{KwTo}{to}
\SetKw{KwRet}{return}%
\SetKw{Return}{return}%
\SetKwBlock{Begin}{begin}{end}%
\SetKwRepeat{Repeat}{repeat}{until}%
%
% --- German keywords
%
% \SetKwInOut{AlgDaten}{Daten}%AlgData
% \SetKwInOut{AlgErgebnis}{Ergebnis}%AlgResult
\SetKwInput{Ein}{Eingabe}%KwIn
\SetKwInput{Aus}{Ausgabe}%KwOut
\SetKwInput{Daten}{Daten}%KwData
\SetKwInput{Ergebnis}{Ergebnis}%KwResult
\SetKw{Bis}{bis}%KwTo
\SetKw{KwZurueck}{zur\"uck}%KwRet
\SetKw{Zurueck}{zur\"uck}%Return
\SetKwBlock{Beginn}{Beginn}{Ende}%Begin
\SetKwRepeat{Wiederh}{wiederhole}{bis}%Repeat
%
% --- Czech keywords
%
% \SetKwInOut{AlgVst}{Vstup}\SetKwInOut{AlgVyst}{V\'{y}stup}
\SetKwInput{Vst}{Vstup}%
\SetKwInput{Vyst}{V\'{y}stup}%
\SetKwInput{Vysl}{V\'{y}sledek}%
%
% --- Portuguese keywords
%
% \SetKwInOut{AlgDados}{Dados}\SetKwInOut{AlgResultado}{Result.}
\SetKwInput{Entrada}{Entrada}%
\SetKwInput{Saida}{Sa\'{i}da}%
\SetKwInput{Dados}{Dados}%
\SetKwInput{Resultado}{Resultado}%
\SetKw{Ate}{at\'{e}}
\SetKw{KwRetorna}{retorna}%
\SetKw{Retorna}{retorna}%
\SetKwBlock{Inicio}{in\'{i}cio}{fim}%
\SetKwRepeat{Repita}{repita}{at\'{e}}%
% --- End 
}
%
%
\newcommand{\algocf@defaults@longend}{%
\algocf@defaults@common
\SetKwIF{gSi}{gSinonSi}{gSinon}{si}{alors}{sinon si}{sinon}{finsi}%
\SetKwIF{Si}{SinonSi}{Sinon}{si}{alors}{sinon si}{sinon}{finsi}%
\SetKwSwitch{Suivant}{Cas}{Autre}{suivant}{faire}{cas o\`u}{autres cas}{fin d'alternative}%
\SetKwFor{Pour}{pour}{faire}{finpour}%
\SetKwFor{PourPar}{pour}{faire en parallèle}{finpour}%
\SetKwFor{PourCh}{pour chaque}{faire}{finprch}%
\SetKwFor{PourTous}{pour tous les}{faire}{finprts}%
\SetKwFor{Tq}{tant que}{faire}{fintq}%
%
\SetKwIF{gIf}{gElsIf}{gElse}{if}{then}{else if}{else}{endif}%
\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}%
\SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{endsw}%
\SetKwFor{For}{for}{do}{endfor}%
\SetKwFor{ForPar}{for}{do in parallel}{endfpar}
\SetKwFor{ForEach}{foreach}{do}{endfch}%
\SetKwFor{ForAll}{forall the}{do}{endfall}%
\SetKwFor{While}{while}{do}{endw}%
%
% --- German for longend
%
\SetKwIF{gWenn}{gSonstWenn}{gSonst}{wenn}{dann}{sonst wenn}{sonst}{Ende-wenn}%gIf
\SetKwIF{Wenn}{SonstWenn}{Sonst}{wenn}{dann}{sonst wenn}{sonst}{Ende-wenn}%gIf
\SetKwSwitch{Unterscheide}{Fall}{Anderes}{unterscheide}{tue}{Fall}{sonst}{Ende-Unt.}%Switch
\SetKwFor{Fuer}{f\"ur}{tue}{Ende-f\"ur}%For
\SetKwFor{FuerPar}{f\"ur}{tue gleichzeitig}{Ende-gleichzeitig}%ForPar
\SetKwFor{FuerJedes}{f\"ur jedes}{tue}{Ende-f\"ur}%ForEach
\SetKwFor{FuerAlle}{f\"ur alle}{tue}{Ende-f\"ur}%ForAll
\SetKwFor{Solange}{solange}{tue}{Ende-solange}%While
%
% --- Portuguese
%
\SetKwIF{gSe}{gSenaoSe}{gSenao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim se}%
\SetKwIF{Se}{SenaoSe}{Senao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim se}%
\SetKwSwitch{Selec}{Caso}{Outro}{selecione}{fa\c{c}a}{caso}{sen\~{a}o}{fim selec}%
\SetKwFor{Para}{para}{fa\c{c}a}{fim para}%
\SetKwFor{ParaPar}{para}{fa\c{c}a em paralelo}{fim para}
\SetKwFor{ParaCada}{para cada}{fa\c{c}a}{fim para cada}%
\SetKwFor{ParaTodo}{para todo}{fa\c{c}a}{fim para todo}%
\SetKwFor{Enqto}{enquanto}{fa\c{c}a}{fim enqto}%
}
%
%
\newcommand{\algocf@defaults@shortend}{%
\algocf@defaults@common
\SetKwIF{gSi}{gSinonSi}{gSinon}{si}{alors}{sinon si}{sinon}{fin}%
\SetKwIF{Si}{SinonSi}{Sinon}{si}{alors}{sinon si}{sinon}{fin}%
\SetKwSwitch{Suivant}{Cas}{Autre}{suivant}{faire}{cas o\`u}{autres cas}{fin}%
\SetKwFor{Pour}{pour}{faire}{fin}%
\SetKwFor{PourPar}{pour}{faire en parallèle}{fin}%
\SetKwFor{PourCh}{pour chaque}{faire}{fin}%
\SetKwFor{PourTous}{pour tous les}{faire}{fin}%
\SetKwFor{Tq}{tant que}{faire}{fin}%
%
%
\SetKwIF{gIf}{gElsIf}{gElse}{if}{then}{else if}{else}{end}%
\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{end}%
\SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{end}%
\SetKwFor{For}{for}{do}{end}%
\SetKwFor{ForPar}{for}{do in parallel}{end}
\SetKwFor{ForEach}{foreach}{do}{end}%
\SetKwFor{ForAll}{forall}{do}{end}%
\SetKwFor{While}{while}{do}{end}%
%
% --- German for shortend
%
\SetKwIF{gWenn}{gSonstWenn}{gSonst}{wenn}{dann}{sonst wenn}{sonst}{Ende}%gIf
\SetKwIF{Wenn}{SonstWenn}{Sonst}{wenn}{dann}{sonst wenn}{sonst}{Ende}%gIf
\SetKwSwitch{Unterscheide}{Fall}{Anderes}{unterscheide}{tue}{Fall}{sonst}{}%Switch
\SetKwFor{Fuer}{f\"ur}{tue}{Ende}%For
\SetKwFor{FuerPar}{f\"ur}{tue gleichzeitig}{Ende}%ForPar
\SetKwFor{FuerJedes}{f\"ur jedes}{tue}{Ende}%ForEach
\SetKwFor{FuerAlle}{f\"ur alle}{tue}{Ende}%ForAll
\SetKwFor{Solange}{solange}{tue}{Ende}%While
%
% --- Portuguese
%
\SetKwIF{gSe}{gSenaoSe}{gSenao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim}%
\SetKwIF{Se}{SenaoSe}{Senao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim}%
\SetKwSwitch{Selec}{Caso}{Outro}{selecione}{fa\c{c}a}{caso}{sen\~{a}o}{fim}%
\SetKwFor{Para}{para}{fa\c{c}a}{fim}%
\SetKwFor{ParaPar}{para}{fa\c{c}a em paralelo}{fim}
\SetKwFor{ParaCada}{para cada}{fa\c{c}a}{fim}%
\SetKwFor{ParaTodo}{para todo}{fa\c{c}a}{fim}%
\SetKwFor{Enqto}{enquanto}{fa\c{c}a}{fim}%
}
%
%
\newcommand{\algocf@defaults@noend}{%
\renewcommand{\a@block}[2]{\a@group{##1}}
\algocf@defaults@common
\SetKwIF{gSi}{gSinonSi}{gSinon}{si}{alors}{sinon si}{sinon}{}%
\SetKwIF{Si}{SinonSi}{Sinon}{si}{alors}{sinon si}{sinon}{}%
\SetKwSwitch{Suivant}{Cas}{Autre}{suivant}{faire}{cas où}{autres cas}{}%
\SetKwFor{Pour}{pour}{faire}{}%
\SetKwFor{PourPar}{pour}{faire en parallèle}{}%
\SetKwFor{PourCh}{pour chaque}{faire}{}%
\SetKwFor{PourTous}{pour tous les}{faire}{}%
\SetKwFor{Tq}{tant que}{faire}{}%
%
\SetKwIF{gIf}{gElsIf}{gElse}{if}{then}{else if}{else}{}%
\SetKwIF{If}{ElsIf}{Else}{if}{then}{else if}{else}{}%
\SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{}%
\SetKwFor{For}{for}{do}{}%
\SetKwFor{ForPar}{for}{do in parallel}{}
\SetKwFor{ForEach}{foreach}{do}{}%
\SetKwFor{ForAll}{forall}{do}{}%
\SetKwFor{While}{while}{do}{}%
% --- German for noend
\SetKwIF{gWenn}{gSonstWenn}{gSonst}{wenn}{dann}{sonst wenn}{sonst}{}%gIf
\SetKwIF{Wenn}{SonstWenn}{Sonst}{wenn}{dann}{sonst wenn}{sonst}{}%gIf
\SetKwSwitch{Unterscheide}{Fall}{Anderes}{unterscheide}{tue}{Fall}{sonst}{}%Switch
\SetKwFor{Fuer}{f\"ur}{tue}{}%For
\SetKwFor{FuerPar}{f\"ur}{tue gleichzeitig}{}%ForPar
\SetKwFor{FuerJedes}{f\"ur jedes}{tue}{}%ForEach
\SetKwFor{FuerAlle}{f\"ur alle}{tue}{}%ForAll
\SetKwFor{Solange}{solange}{tue}{}%While
% --- Portuguese
\SetKwIF{gSe}{gSenaoSe}{gSenao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{}%
\SetKwIF{Se}{SenaoSe}{Senao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{}%
\SetKwSwitch{Selec}{Caso}{Outro}{selecione}{fa\c{c}a}{caso}{sen\~{a}o}{}%
\SetKwFor{Para}{para}{fa\c{c}a}{}%
\SetKwFor{ParaPar}{para}{fa\c{c}a em paralelo}{}
\SetKwFor{ParaCada}{para cada}{fa\c{c}a}{}%
\SetKwFor{ParaTodo}{para todo}{fa\c{c}a}{}%
\SetKwFor{Enqto}{enquanto}{fa\c{c}a}{}%
}
%
%%
%%
%%
%
% default macros are:
\defaultsmacros@algo
\SetNoline
%
%
%
%%
%%%
%%%% END