4

I have problems to make the below formula look great. Do you have any ideas on how I can make it look better? enter image description here

This is this LaTeX code I have for it:

PTK = $PRF(PMK, \text{"Pairwise key expansion"} || Min(AA, SPA) || \\ Max{AA, SPA}|| Min(ANonce, SNonce) ||  Max(ANonce,SNonce))$

I appreciate all help!

Johan
  • 65

4 Answers4

9

Taking Ignasi's approach a step further...

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{split}
\text{PTK} =  \text{PRF}\bigl( &\text{PMK}, \text{``Pairwise key expansion''} \\& || \min(\text{AA}, \text{SPA})  \\ 
& || \max(\text{AA}, \text{SPA})\\&|| \min(\text{ANonce}, \text{SNonce}) \\&||  \max(\text{ANonce},\text{SNonce})\bigr)
\end{split}
\]
\end{document}

enter image description here

MFGA

  • Thanks a lot for the great answer, I'll go for this one! – Johan Mar 15 '19 at 10:44
  • 2
    @Johan Thanks. While you can click the up-arrow to "upvote" any question or answer on this site that you find helpful, you can select only one answer for each of your questions to click the check on, as a means to "accept" the most suitable answer. – Steven B. Segletes Mar 15 '19 at 10:49
8

I don't know if it looks great, but do you want something like this?

enter image description here

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
\begin{split}
\text{PTK} = & \text{PRF}\left( \text{PMK}, \text{"Pairwise key expansion"} || \min(\text{AA}, \text{SPA}) || \right. \\ 
& \left. \qquad \max(\text{AA}, \text{SPA})|| \min(\text{ANonce}, \text{SNonce}) ||  \max(\text{ANonce},\text{SNonce})\right)
\end{split}
\]

\end{document}
Ignasi
  • 136,588
5

IMHO your formula is in an algorithm and || stands for "or". So you should have a look at algorithm packages. Anyway this is a non-algorithm but algorithmic answer:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{array}{r@{}l@{}l}
    \text{PTK}=PRF&(PMK, & \text{``Pairwise key expansion''}\\
    && || \min(AA,SPA)\\
    && || \max(AA,SPA)\\
    && || \min(ANonce,SNonce)\\
    && || \max(ANonce,SNonce)\\
    &)&
\end{array}
\]
\end{document}

enter image description here

Edit 1: Improved version

I prefer this way.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{array}{rl}
    \text{PTK}=PRF(&\\
    & PMK,\\
    & (\\
    & \quad\text{``Pairwise key expansion''}\\
    & \quad||\min(AA,SPA)\\
    & \quad||\max(AA,SPA)\\
    & \quad||\min(ANonce,SNonce)\\
    & \quad||\max(ANonce,SNonce)\\
    & )\\
    )&
\end{array}
\]
\end{document}

enter image description here

  • Alright thanks a lot! I'm not so good at LaTeX so I'll go for this one, since it looks much better than before! Not sure how much algorithm package would have improved it, but this looks good enough. – Johan Mar 15 '19 at 10:43
  • @Johan I already improved my answer. –  Mar 15 '19 at 10:46
2

I have two proposals. Most important is to properly define macros for specific object types in your document, in order to ensure uniformity.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\OOR}{\mathrel{\|}}
\newcommand{\tvar}[1]{\mathrm{#1}}
\newcommand{\tdesc}[1]{\textup{``#1''}}

\begin{document}

\[
\begin{aligned}
\tvar{PTK}=\tvar{PRF}\bigl(
 &\tvar{PMK},\tdesc{Pairwise key expansion} \\
 & \OOR \min(\tvar{AA},\tvar{SPA})\\
 & \OOR \max(\tvar{AA},\tvar{SPA})\\
 & \OOR \min(\tvar{ANonce},\tvar{SNonce})\\
 & \OOR \max(\tvar{ANonce},\tvar{SNonce}) \bigr)
\end{aligned}
\]

\begin{multline*}
\tvar{PTK}=\tvar{PRF}\bigl(
 \tvar{PMK},\tdesc{Pairwise key expansion}
 \OOR \min(\tvar{AA},\tvar{SPA}) \OOR \\
 \max(\tvar{AA},\tvar{SPA})
 \OOR \min(\tvar{ANonce},\tvar{SNonce})
 \OOR \max(\tvar{ANonce},\tvar{SNonce}) \bigr)
\end{multline*}

\end{document}

enter image description here

egreg
  • 1,121,712