# Tag Info

18

So, first let me say that this is probably the most thoroughly researched question I've read so far. Congratulations. I'll be reusing some of David's comments. The hashing algorithm takes the csname as an array of bytes (probably some differences there for XeTeX and LuaTeX, let me focus on 8-bit engines) and computes the sum of csname[i]*2^(len-i) % prime ...

13

The respective TeX code is @<Compute the hash code |h|@>= h:=buffer[j]; for k:=j+1 to j+l-1 do begin h:=h+h+buffer[k]; while h>=hash_prime do h:=h-hash_prime; end So basically each digit gets mapped to some 2^k mod p. Prefixes and postfixes don't actually make the hashing worse, but the somewhat peculiar structure of the hash table means ...

12

Yes, LaTeX is a good tool to produce such documents. Especially the moderncv class is very nice for resumes. Adding URLs is not a problem in LaTeX. However, there is a certain learning curve involved and it might take you a little while to get your first complex document in the form you want. Nowadays there many editor and tools like latexmk that will help ...

12

With LuaTeX you can use the script language Lua: \documentclass{article} \usepackage{luacode} \begin{luacode} function permute(n) local tab = {} for i = 1, n do tab[i] = i end for i = 1, n do local j = math.random(i, n) tab[i], tab[j] = tab[j], tab[i] end for i = 1, n do tex.print("\\shortstack{"..i.."\\\\"..tostring(tab[i]).."} ") ...

11

For the special case, there is also a cheap solution. \and can be redfined for hyperref's pdfauthor: \documentclass{article} \usepackage{hyperref} \pdfstringdefDisableCommands{\def\and{, }} \newcommand*{\authors}[1]{% \hypersetup{pdfauthor={#1}}% \author{#1}% } \title{Test document} \authors{John Doe\and Dark Vador\and Yoda}% without space before \...

11

Load the hyperref package first, and then set the PDF document properties using \hypersetup: \documentclass{article} \usepackage{hyperref}% http://ctan.org/pkg/hyperref \newcommand{\authors}[1]{ {\renewcommand{\and}{\unskip, }\hypersetup{pdfauthor={#1}}} \author{#1} } \title{My title} \authors{John Doe \and Dark Vador \and Yoda} \begin{document} \...

11

The 'classical' way to store values with a key is to use a csname-based approach \def\addvalue#1#2{\expandafter\gdef\csname my@data@#1\endcsname{#2}} \def\usevalue#1{\csname my@data@#1\endcsname} To allow arbitrary material in the key, you can use e-TeX's \detokenize, and also add a test for undefined values if you wish \def\addvalue#1#2{\expandafter\...

10

The short-term answer is: use token lists nested in a sequence. \RequirePackage{expl3} \ExplSyntaxOn \seq_new:N \l_lines_seq \cs_new:Npn \jb_wrap:n #1 { \exp_not:n { {#1} } } \seq_clear:N \l_lines_seq \seq_set_split:Nnn \l_tmpa_seq { \\ } { a & b \\ c & d } \seq_map_inline:Nn \l_tmpa_seq { \seq_set_split:Nnn \l_tmpb_seq { & } {#1} % use ##...

9

Here's an implementation of the Knuth shuffle algorithm with expl3. \documentclass{article} \usepackage{amsmath,xparse} \input{random} \ExplSyntaxOn \cs_new_eq:NN \knuthshuffle_get_random:Nnn \setrannum \tl_new:N \l_knuthshuffle_tempa_tl \tl_new:N \l_knuthshuffle_tempb_tl \int_new:N \l_knuthshuffle_random_int \prop_new:N \l_knuthshuffle_newperm_prop \...

8

You have several unprotected end of lines, which count as spaces. Some of those I added are not really relevant, but it's good practice to add them. \def\newdict #1{% \expandafter\edef\csname #1 \endcsname{#1}% \expandafter\def\csname #1.set \endcsname##1##2{% <-- Important \expandafter\def\csname #1.##1\endcsname{##2}% }% \expandafter\def\...

8

Well, I guess I can help. :-) Code \documentclass{scrartcl} \usepackage{tikz} \usetikzlibrary{shapes,arrows,calc} \newcommand{\data}{data \nodepart{second} \phantom{null}} \tikzstyle{ptr} = [draw, -latex'] \tikzstyle{head} = [rectangle, draw, text height=3mm, text width=3mm, text centered, node distance=3cm, inner sep=0pt] \tikzstyle{data} = [rectangle ...

8

Basic Solution: Without more details it is difficult to know if something as simple as this will work for you: You call \myfirstauthor{Kenobi}{General}{1138}, and then to access each member you simply refer to \myfirstauthorName, \myfirstauthorRank, and \myfirstauthorSerialNum: \documentclass{article} \newcommand{\myfirstauthor}[3]{% \newcommand{\...

7

You can also use the pgfkeys library for a slightly different approach, using a key value system, which is designed as a tree structure. First you define a family, \pgfkeys{/combo/.is family} and then the keys, \pgfkeys{/combo left/.store in=\left@c, left/.default=0, right/.store in=\right@c ...} You can set default values: \def\...

7

Here is a generalized solution similar to Python's tuples in six lines of TeX code. \documentclass{article} \makeatletter \def\tuple#1=(#2 #3 #4){% \expandafter\def\csname#1@1\endcsname{#2} \expandafter\def\csname#1@2\endcsname{#3} \expandafter\def\csname#1@3\endcsname{#4} } \def\xtuple#1#2{% \csname#1@#2\endcsname } \makeatother \begin{...

7

You can use the bytefield package, developed exactly with the purpose of drawing protocol packet structures. An example taken from the manual: \documentclass[border=10pt,png]{standalone} \usepackage{bytefield} \begin{document} \begin{bytefield}[bitwidth=1.1em]{32} \bitheader{0-31} \\ \begin{rightwordgroup}{RTP \\ Header} \bitbox{2}{V=2} & \bitbox{1}{...

7

The way that sequences are implemented means that at that level they can be nested (the nested sequences will be distinct from the outer one). However, what is not available is an interface to store or recover the whole of a sequence. \seq_get:NN \l_my_main_seq \l_tmpa_tl % Available \seq_set:NV \l_my_daughter_seq \l_tmpa_tl % Not available. Similarly, we'...

7

You can define an array that's loaded with the relatives to a root, when \entryword is processed. When you use \entryroot, the array is printed. \documentclass{article} \usepackage[english]{babel} \usepackage{xparse} \NewDocumentCommand{\entryprompt}{mm}{% \par\noindent\textbf{\textsf{#1}} #2% } \ExplSyntaxOn \NewDocumentCommand{\entryword}{ommm} { \...

6

booktabs sets the default widths in a font dependent way (em units) but it seems that revtex does not set up the font until \begin{document} so you need to delay setting the rule widths: \documentclass{revtex4} \usepackage{array,mathtools,amssymb,booktabs} \newcolumntype{C}{>{$}c<{$}} \AtBeginDocument{ \heavyrulewidth=.08em \lightrulewidth=.05em \...

6

A starting point: The code: \documentclass[border=2pt]{standalone} \usepackage{tikz} \usetikzlibrary{matrix,positioning,arrows.meta,arrows} \tikzset{ mymat/.style={ matrix of math nodes, text height=2.5ex, text depth=0.75ex, text width=3.25ex, align=center, column sep=-\pgflinewidth }, mymats/.style={ mymat, nodes={draw,fill=#1} } }...

6

Currently, expl3 provides the prop data type for key-value type addressing \prop_put:Nnn \l_tmpa_prop { a } { data-for-a } \tl_set:Nx \l_tmpa_tl { \prop_get:Nn \l_tmpa_prop { a } } \tl_show:N \l_tmpa_tl % "data-for-a" At present, this is also implemented using a single underlying macro so extraction in an expandable way has to iterate over the content. ...

5

It's possible to do this, the main disadvantage of course is they are global. Having loaded the font you can use other parts of its structure as well. This old TUGBoat paper of Jonathan Fine's discusses using the ligature tables of such fake fonts to encode state machines.

5

The real application is almost trivial with xparse and expl3. \documentclass{article} \usepackage{xparse} \usepackage{hyperref} \ExplSyntaxOn \NewDocumentCommand{\authors}{O{,}m} { \legat_authors:nn { #1 } { #2 } } \seq_new:N \g_legat_authors_seq \cs_new_protected:Npn \legat_authors:nn #1 #2 { \seq_gset_split:Nnn \g_legat_authors_seq { #1 } { #2 } ...

5

\documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\definetuple}{mmmm} { \tl_new:c { g_tuple_#1_tl } \tl_gset:cn { g_tuple_#1_tl } { {#2} {#3} {#4} } } \DeclareExpandableDocumentCommand{\extractfromtuple}{mm} { \tl_item:cn { g_tuple_#1_tl } { #2-1 } } \ExplSyntaxOff \begin{document} \definetuple{alice}{Alice}{...

4

Only an answer based on percusse's fine solution but with some modifications for the styles. I try to get a lighter code. I added a scope to use options for the labels. I removed pos=.5 because it's the value by default. I remove the style myline and I placed the options in the scope. I used the possibility to draw several edges from the same vertex with one ...

4

Here is something with lots of different options in action. You can then opt for some library with more specialization towards trees and graphs however I recommend getting used to the TikZ language first before such attempt. \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[>=stealth,%some style declarations myline/....

4

Define a \Struct that matches one of the existing structures within the algorithm2e framework. In this case, it resembles a repeat ... until, so I'd use \SetKwRepeat{Struct}{struct \{}{\}}: \documentclass{article} \usepackage[noline]{algorithm2e} \SetKwRepeat{Struct}{struct \{}{\}}% \newcommand{\Float}{\KwSty{float}} \begin{document} \begin{algorithm}[...

3

Using lambda lists: \documentclass{minimal} \usepackage{lambda} % http://www.ctan.org/pkg/lambda-lists % \def\createcontact#1#2#3{\Listize[#1,#2,#3]} \let\extractfirst\Head \def\extractsecond#1{\extractfirst{\Tail{#1}}} \def\extractthird#1{\extractsecond{\Tail{#1}}} % \newcommand{\myfirstauthor}{\createcontact{Alice}{Munich}{Germany}} \newcommand{\...

3

With credit to Bruno Le Floch for the idea, here is what I would consider "working for me": \documentclass{standalone} % ONE POSSIBLE SOLUTION \newcommand{\createcontact}[3]{} \newcommand{\extractfirst}[1]{\renewcommand{\createcontact}[3]{##1}#1} \newcommand{\extractsecond}[1]{\renewcommand{\createcontact}[3]{##2}#1} \newcommand{\extractthird}[1]{\...

3

Proper alignment using listings is possible by setting the font to typewriter (basicstyle=\ttfamily as optional parameter, or by using \lstset): \documentclass{article} \usepackage{filecontents}% http://ctan.org/pkg/filecontents \usepackage{listings}% http://ctan.org/pkg/listings ​\begin{document} % Taken from http://en.wikipedia.org/wiki/FASTA_format#...

3

Perhpas the tkz-linknodes package can be useful for your purpose; here's a little schematic example: \documentclass{article} \usepackage{graphicx} \usepackage{tkz-linknodes} \tikzset{ArrowStyle/.style={text=black,shorten >= 15pt,shorten <= 15pt}} \tikzset{LabelStyle/.style={pos=0.25,right,font=\scriptsize}} \tikzset{NodeStyle/.style={inner sep=0pt}} ...

Only top voted, non community-wiki answers of a minimum length are eligible