2

I am trying to do a dimensional calculation, but LaTeX reads over parts of my equation. How do I correctly calculate BLLa here?

Sorry for the not that minimum example.

\documentclass{article}
\usepackage{etex}
\usepackage{etoolbox}
\usepackage{minted}
\usepackage[skins]{tcolorbox}
\usepackage{lineno}
\makeatletter
\def\gobble#1{}
\renewcommand\DeleteFile[1]{}
\definecolor{mintedbg}{HTML}{F8FAFF}
\definecolor{col1}{HTML}{80B2FF} %4 Outer right borderline
\definecolor{col2}{HTML}{99C2FF} %3
\definecolor{col3}{HTML}{B2D1FF} %2
\definecolor{col4}{HTML}{CCE0FF} %1 Outer left borderline
\newdimen\BLW
\BLW\dimexpr 3pt\relax
\newdimen\BLS
\BLS\dimexpr .5pt\relax
\newdimen\BLLa
\BLLa\dimexpr -.5\BLW-\BLS-.5 *.75\BLW \relax
\newdimen\BLLb
\BLLb\dimexpr -.5\BLW-\BLS-.5(.75\BLW)-\BLS-.5(.75^2 \BLW)\relax
\BeforeBeginEnvironment{Rcode}{%
\begin{trivlist}
\item\begin{tcolorbox}[
  width=\linewidth-6pt,
  enlarge top by=3pt,
  enlarge bottom by=3pt,
  enlarge left by=3pt,
  enlarge right by=3pt,
  frame hidden,boxrule=0pt,
  top=1mm,
  bottom=1mm,
  colback=mintedbg,
  freelance,
  arc=0pt,
  outer arc=0pt,
  boxrule=0pt,
  frame code={
    \draw[col1,line width=\BLW]  % right
      ([xshift=0pt]frame.north west) -- ([xshift=0pt]frame.south west);
    \draw[col2,line width=\BLW*(3/4)] 
      ([xshift=\BLLa]frame.north west) -- ([xshift=\BLLa]frame.south west);
    \draw[col3,line width=\BLW*(3/4)^2] 
      ([xshift=\BLLb]frame.north west) -- ([xshift=\BLLb]frame.south west);
    \draw[col4,line width=\BLW*(3/4)^3] 
      ([xshift=-7.5pt]frame.north west) -- ([xshift=-7.5pt]frame.south west);
  }
]}
\AfterEndEnvironment{Rcode}{\end{tcolorbox}\end{trivlist}}%

\pgfkeys{
    /terminal/.cd,
    caption/.code={\pgfkeyssetvalue{terminal/caption}{\caption{#1}}}, % Double hash for expansion
    label/.code={\pgfkeyssetvalue{terminal/label}{\label{#1}}},
}
\pgfkeyssetvalue{terminal/label}{}
\pgfkeyssetvalue{terminal/caption}{\caption{}}
\newenvironment{Rcode}{%
  \VerbatimEnvironment
  \minted@resetoptions
  \setkeys{minted@opt}{}
  \begin{center}
    \begin{minipage}{\linewidth}    
      \begin{VerbatimOut}{\jobname.pyg}}
{%
      \end{VerbatimOut}
      \minted@pygmentize{r}
      \DeleteFile{\jobname.pyg}
    \end{minipage}
    \end{center}}
    \makeatother

    \begin{document}
    \begin{Rcode}
# Here a piece of R code that we've 
# all come to know and love
object <- c(1,2,5,8)
\end{Rcode} 
\end{document}

I am aware LaTeX will expand all the way to \BLW (after *.75), but I don't know how to stop LaTeX from reading that and discarding *.75.

1010011010
  • 6,357

2 Answers2

2

\dimexpr syntax is quite restricted as it basically encodes a sequence of \advance, \multiply and \divide statements.

texdoc etex should yield a document containing a formal grammar.

In the case of

\BLLa\dimexpr -.5\BLW-\BLS-.5 *.75\BLW \relax

you can't just multiply something by a dimensionless fraction. In fact, a fractional expression like .5 is only allowed as a prefix to a length or skip register (or \dimexpr). So allowed alternatives are

\BLLa\dimexpr -.5\BLW-\BLS-.5\dimexpr.75\BLW\relax \relax
\BLLa\dimexpr -.5\BLW-\BLS-.75\BLW/2 \relax
\BLLa\dimexpr -.5\BLW-\BLS-.375\BLW \relax
  • Two questions here: 1. Where does the second \relax come from and why do I use it? I'd like to know the reasoning behind that. 2. is it possible to take the power of a function (e.g. .75^2) to use in my expression? – 1010011010 May 17 '14 at 12:45
  • 1
  • Its always \dimexpr...\relax. Two \dimexpr, two \relax. 2. No.
  • – Stephan Lehmke May 17 '14 at 12:47
  • I was missing a heads up that I didn't check the box. ;-) – 1010011010 May 17 '14 at 16:06