2

So I'm new to Lyx and LaTeX. I was trying to create a programming list with some information which includes math symbols. Especially I would like to use the "〉" symbol (link) and the similar one. Tried to find a solution or a similar thread which speaks about this issue and I found the following thread (link). Problem is I don't really know LaTeX so I was wondering if there is a way to do so in a through the options of LyX. I would like the output to be:

rhs = "〈",rhs ,"〉"

How can I do it?

1

3 Answers 3

8
+50

If you want to use math symbols in a program listing in LyX, you should add the parameter Document > Settings... > Listings

mathescape=true

enter image description here

This will allow you to use $...$ to escape to regular (La)TeX within a listing. Here's the output without mathescape=true:

enter image description here

Here's the output with mathescape=true:

enter image description here

0
3

If you're simply looking for the code that produces the mathematical symbol:

In math mode: \langle and \rangle. For brackets that stretch: \left\langle and \right\rangle.

In text mode you will need the textcomp package, and then use \textlangle and \textrangle.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{textcomp}               % For using \langle in text

\begin{document}
This is a working example of using \textlangle  or \textrangle in text by simply 
importing the textcomp package (see pre-amble). If instead you want to use it in math 
mode, you could either do $\langle$ or $\rangle$ or you could use it in an equation 
as such:

\begin{equation}
    \langle
\end{equation}

\begin{equation}
    \rangle
\end{equation}

\end{document}
2
  • Please can you explain in more detail your answer? I not use LyX since 2005.
    – Sebastiano
    Commented Nov 25, 2018 at 16:44
  • I've added a working example for you. Please let me know if you would want to implement it using the GUI instead, I might have misunderstood the essence of your question. Commented Nov 26, 2018 at 11:41
2

Here is an advanced example using lstlistings, more or less copied verbatim from a production version.

 \lstdefinestyle{steden}{basicstyle=\ttfamily,
    keywordstyle=\color{blue}\bfseries\ttfamily,
    stringstyle=\color{yac}\ttfamily,
    showstringspaces=false,
    commentstyle=\color{darkgray}\sl\ttfamily,
    emph={process,new,parfill,multifill,release,fetch,releaseAll,fetchAll,spawn,processDC,\#}, 
    emphstyle={\color{blue}\bfseries},
    emph={[2]ChanName,Process,RD,Trans,NFData,reduce,fold,parMapDC,reduceDC,parMapAt,map_par,map_farm,map_wp,parMap,farm,ssf,workpool,par,pseq},
    emphstyle={[2]\color{blue}\bfseries},
    emphstyle={[3]\color{red}\bfseries},
    emph={[3]r0,rwhnf,rnf,rdeepseq,unsafePerformIO,IO,merge},
    captionpos=b,
    lineskip=-0.1ex,
    frame=lines,
    language=Haskell,
    literate={+}{{$+$}}1 {/}{{$/$}}1 {*}{{$*$}}1 {=}{{$=$}}1
             {`+`}{{+}}1  {`-`}{{-}}1 {`*`}{{*}}1 
             {>}{{$>$}}1 {<}{{$<$}}1 {\\}{{$\lambda$}}1 {\\n}{{\textbackslash
             n}}2 {\\\\}{{\char`\\\char`\\}}1
             {->}{{$\rightarrow$}}2 {>=}{{$\geq$}}2 
             {<-}{{$\in$}}2 % the list comprehension <-
             {<--}{{$\leftarrow$}}2 % the monadic <-
             {<=}{{$\leq$}}2 {=>}{{$\Rightarrow$}}2
             {\ .\ }{{ $\circ$ }}3     
             {(.)}{{($\circ$)}}3     
             {>>}{{>>}}2 {>>=}{{>>=}}2 {/=}{{$\neq$}}2
             {|}{{$\mid$}}1
%%% vector operations
             {v+}{{$\overrightarrow{+}$}}1 {v-}{{$\overrightarrow{-}$}}1
             {v*}{{$\overrightarrow{\cdot}$}}1
%%% number fields
             {NN}{{$\N$}}1 {ZZ}{{$\Z$}}1 {QQ}{{$\Q$}}1
             {xdd}{{$\delta$}}1
             {xaa}{{$\alpha$}}1
%%% further hacks
             {`l_p`}{{l\textsubscript{p}}}2 
             {`=`}{{$=$}}1
             {p^k}{{p\textsuperscript{k}}}2
             {`p^k`}{{p\textsuperscript{k}}}2
             {`^2`}{{\textsuperscript{2}}}1
             {`xsinn`}{{$\zeta_n^n$}}2
             {bottom}{{$\bot$}}1
%% do not highlight "reduce" in a special case
             {xreduce}{{reduce}}6
             }

Further environments for simpler usage:

\lstnewenvironment{code*}
   {%
     \lstset{style=steden,
    }} {}
\newcommand{\cd}[1]{\lstinline[style=steden,keepspaces=true,
breaklines=true,basicstyle=\ttfamily];#1;}             
\newcommand{\inputcode}[1]{\lstinputlisting[style=steden,xleftmargin=0pt,
    xrightmargin=0pt]{#1}}

\lstnewenvironment{code}
   {%
     \lstset{style=steden,
    frame=none,
    xleftmargin=30pt,
    xrightmargin=10pt,
    }} {}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .