Tag Info

Hot answers tagged

17

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

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 ...


9

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

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 ...


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]{% ...


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}% }% ...


8

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 ...


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} { ...


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: ...


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 ...


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, ...


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

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} & ...


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} } ...


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

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

\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} ...


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 ...


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

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} ...


3

My answer tries to explain why @soze got that strange result. First of all, when in dot you define colors, you have to use the same syntax of xcolor, thus: fillcolor="grey75" is wrong => fillcolor="gray!75" color="darkorchid3" is wrong again => color="DarkOrchid3" Another thing: the record shape gives me errors for each node, while using shape ...


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}} ...


3

%!TEX TS-program = pdftex \catcode`@=11 \long\def\@firstoftwo#1#2{#1} \long\def\@secondoftwo#1#2{#2} \def\first#1{\@firstoftwo#1} \def\last#1{\@secondoftwo#1} \catcode`@=12 \first{{+tokens1+}{--tokens2--}} \last{{+tokens1+}{--tokens2--}} \bye Of course, if you don't have (or want) anything to do with LaTeX. There's no need for \@firstoftwo while ...


3

Another solution without the need of any package (because only TeX primitives and basic macros are used): \def\sxdef#1{\expandafter\xdef\csname#1\endcsname} \def\entryword{\def\opt{}\futurelet\next\entrywordA} \def\entrywordA{\ifx\next[\expandafter\entrywordB \else \expandafter\entrywordC \fi} \def\entrywordB[#1]{\def\opt{#1}\entrywordC} ...


3

This is a demonstration suitable for further editing, the skeleton is programmed in LuaLaTeX. We store all the words and roots in two external files and load them on next TeX runs. The key line is \newcommand\entryword[4][]{\directlua{storeword([[#1]],[[#2]],[[#3]],[[#4]])}} which passes all TeX arguments to Lua, into the storeword function in this ...



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