I would like to be able to make a single word in a text look like a coded word. Is there any command such as \code{...}
which allows me to do so?
(basically, I want to produce something like above for the "\code{…}" part)
codefonts
I would like to be able to make a single word in a text look like a coded word. Is there any command such as \code{...}
which allows me to do so?
(basically, I want to produce something like above for the "\code{…}" part)
(Improved answer thanks to Bruno's help on his code)
I've implemented some of the things I mentioned in my earlier answer, but I felt this was different enough to get a separate answer.
Once again, tex.sx provided me with a couple of things I needed for this. Bruno Le Floch wrote some code that rotates arguments at a random angle and helped shortening it for this answer. Martin Scharrer showed how to execute a command for every word. Thanks to both of them.
Starting at the top of the code, here's what I did to change the design:
extarticle
document class\eldersign
that inserts an elder sign, sized in relation to the current font size. You need to find an elder sign that you can use, I put in the placeholder eldersignimagefile
. I recommend using a PNG image or some other format providing background transparency.fontspec
, as I described in my other answer. (I haven't tested Bruno's and Martin's code with XeLaTeX though.) With a different font, you might want to choose a different font size and different rotation angles.backgroundimagefile
MidnightBlue
(svgnames
color scheme)Whenever you want to typeset text crazily, you have to pass it as an argument to \cthulhu
. For an elder sign, just use \eldersign
. You might want to adapt your image to suit the text color.
This is just hacked together and you will very likely run into problems once you start using it more extensively. Take it as inspiration. It was fun for me putting it together. Feel free to make suggestions on how to improve this.
\documentclass[17pt]{extarticle}% This is a document class providing more font size options
\usepackage[svgnames]{xcolor}
\usepackage{graphicx}
\usepackage{emerald}% font package
\usepackage[doublespacing]{setspace}% line spacing
\usepackage[T1]{fontenc}
\usepackage{wallpaper}
% thanks to Bruno Le Floch: https://tex.stackexchange.com/q/9331/4012
% and in his comments to https://tex.stackexchange.com/a/29458/4012
\usepackage{rotating}
\usepackage[first=-6,last=6]{lcg}% you can play around with these values
\makeatletter
\newcommand{\globalrand}{\rand\global\cr@nd\cr@nd}
\makeatother
\newcommand{\randomrotation}[1]{\globalrand\turnbox{\value{rand}}{#1}\phantom{#1}}
% thanks to Martin Scharrer: https://tex.stackexchange.com/q/11598/4012
\makeatletter
\def\cthulhu#1{%
\@cthulhu#1 \@empty
}
\def\@cthulhu#1 #2{%
\randomrotation{#1}\space
\ifx #2\@empty\else
\expandafter\@cthulhu
\fi
#2%
}
\makeatother
% ----------
\newcommand{\eldersign}{\raisebox{-.5\height}{\includegraphics[height=3ex]{eldersignimagefile}}}
\renewcommand*{\rmdefault}{fts}
\begin{document}\pagestyle{empty}\CenterWallPaper{}{backgroundimagefile}
\centering% that madman wouldn't justify his writings
\color{MidnightBlue}% my pick for "looks like ink"
\cthulhu{Hello, I am crazy. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed.} \eldersign
\end{document}
On the other points you mentioned: I don't think Dropcaps would look good here; they convey something of a plannedness which wouldn't be in the style of my madman. As for font size changes and random word spacing, I don't know how to do that automarandomly.
I was able to replicate it pretty closely using listings
.
Ultimately, the part that made it tricky is that you have redundant commands in your \lstset
(and presumably also where you defined keywords for Javascript): for example, the colors you provided for different keyword styles were overridden by others that were already defined.
I started with a listings
language definition for Javascript, which I got from this TeX.sx post; however, we'll be modifying the colors, so I removed the definitions we won't use.
\lstdefinelanguage{JavaScript}{
keywords={typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break},
ndkeywords={class, export, boolean, throw, implements, import, this},
sensitive=false,
comment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]',
morestring=[b]"
}
Then, we define the style, which comes from setting the colors (and italics for comments) in keywordstyle
, commentstyle
, etc., along with a few spacing adjustments. I always alphabetize my \lstset
call so that I can quickly figure out whether I've already added a command rather than duplicating it.
\lstset{
aboveskip={1.3\baselineskip},
basicstyle=\scriptsize\ttfamily\linespread{4},
breaklines=false,
columns=flexible,
commentstyle=\color[rgb]{0.127,0.427,0.514}\ttfamily\itshape,
escapechar=@,
extendedchars=true,
frame=single,
identifierstyle=\color{black},
inputencoding=latin1,
keywordstyle=\color[HTML]{228B22}\bfseries,
language=JavaScript,
ndkeywordstyle=\color[HTML]{228B22}\bfseries,
numbers=left,
numberstyle=\tiny,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
showstringspaces=false,
stringstyle=\color[rgb]{0.639,0.082,0.082}\ttfamily,
upquote=true
}
Finally, minted
highlights the numbers in gray. This TeX.sx answer shows us how to do it in listings
:
\definecolor{darkgray}{rgb}{.4,.4,.4}
\lstset{literate=%
*{0}{{{\color{darkgray}0}}}1
{1}{{{\color{darkgray}1}}}1
{2}{{{\color{darkgray}2}}}1
% ... and so on
{9}{{{\color{darkgray}9}}}1
}
Here's my whole working example.
\documentclass{article}
\usepackage{xcolor}
\usepackage{textcomp}
\usepackage{listings}
\definecolor{darkgray}{rgb}{.4,.4,.4}
\lstdefinelanguage{JavaScript}{
keywords={typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break},
ndkeywords={class, export, boolean, throw, implements, import, this},
sensitive=false,
comment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]',
morestring=[b]"
}
\lstset{
aboveskip={1.3\baselineskip},
basicstyle=\scriptsize\ttfamily\linespread{4},
breaklines=false,
columns=flexible,
commentstyle=\color[rgb]{0.127,0.427,0.514}\ttfamily\itshape,
escapechar=@,
extendedchars=true,
frame=single,
identifierstyle=\color{black},
inputencoding=latin1,
keywordstyle=\color[HTML]{228B22}\bfseries,
language=JavaScript,
ndkeywordstyle=\color[HTML]{228B22}\bfseries,
numbers=left,
numberstyle=\tiny,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
stringstyle=\color[rgb]{0.639,0.082,0.082}\ttfamily,
upquote=true,
showstringspaces=false,
}
\lstset{literate=%
*{0}{{{\color{darkgray}0}}}1
{1}{{{\color{darkgray}1}}}1
{2}{{{\color{darkgray}2}}}1
{3}{{{\color{darkgray}3}}}1
{4}{{{\color{darkgray}4}}}1
{5}{{{\color{darkgray}5}}}1
{6}{{{\color{darkgray}6}}}1
{7}{{{\color{darkgray}7}}}1
{8}{{{\color{darkgray}8}}}1
{9}{{{\color{darkgray}9}}}1
}
\begin{document}
\lstinputlisting{filename.js}
\end{document}
Best Answer
Normally a monospaced font is used for this. This is accomplished with
\texttt{...}
. If you want to use code, you can use\def\code#1{\texttt{#1}}
. From that point on you can write\code{...}
to get monospaced output.