2

I'm trying to align the content of an expression when in math mode. Note: I've seen a lot of questions that may look similar to this but what I'm asking is not the alignement inside an equation block. In other words, I want my equation to be inserted in line: to this scope I use $$ to delimit my equation in the text but when the expression inside $$ is too long it goes further the vertical alignement and a new line is inserted only when it terminates.

EDIT: From my document:

\documentclass{article}
\begin{document}
[...]then, adding a version counter would turn such policy into "$ECU\_MODEL\_2247\_v\_0 \; \textbf{OR} \; \textbf{(} CAR\_MODEL\_21\_v\_0 \; \textbf{AND} \; ECU\_MODEL\_2248\_v\_0 \textbf{)}$". If a key now gets compromised, then the manufacturer updates the version of the access policy, that now becomes "$ECU\_MODEL\_2247\_v\_1 \; \textbf{OR} \; \textbf{(} CAR\_MODEL\_21\_v\_1 \; \textbf{AND} \; ECU\_MODEL\_2248\_v\_1 \textbf{)}$"[...]
\end{document}

The text inside $$ goes beyond the alignement but I don't want to put it in an equation block because I would like it to be "inline" as in the document I reported.

  • 1
    Welcome to TeX.SE. Please edit your posting to provide a specific example of material you wish to format in a certain way. Please also clarify what, specifically, you wish to achieve. – Mico Jan 13 at 13:43
  • @Mico thanks for the suggestions! I edited my question. Hope it is clear now – user1108 Jan 13 at 13:54
1

I'd like to suggest that you load the xurl package and use its \path macro to typeset the long name labels. That way, line breaks inside the long labels are allowed to occur wherever they're needed. (The \path macro is a close relative of the \url macro; the only real difference is that hyperref won't attempt to make the argument of \path into a clickable URL string.)

In addition, I would also like to suggest that you not bold-face the AND and OR terms; instead, consider typesetting them in small-caps.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc} % for robust-looking _ (underscore) characters
\usepackage{xurl}
\newcommand\logic[1]{\textsc{\MakeLowercase{#1}}}
\begin{document}
\noindent
[\dots] then, adding a version counter would turn such policy into 
``\path{ECU_MODEL_2247_v_0} \logic{OR} (\path{CAR_MODEL_21_v_0} 
\logic{AND}  \path{ECU_MODEL_2248_v_0})''. 
If a key now gets compromised, then the manufacturer updates the 
version of the access policy, which now becomes 
``\path{ECU_MODEL_2247_v_1} \logic{OR} (\path{CAR_MODEL_21_v_1} 
\logic{AND} \path{ECU_MODEL_2248_v_1})'' [\dots]
\end{document}

Addendum: Of course, typesetting the long-ish expressions in a display format would very likely make them easier to read, whether or not a line break occurs.

enter image description here

To my untrained eye at least, displaying the expressions on lines by themselves makes it much easier to go back and forth and figure out what the pre- and post-conditions are.

\documentclass{article}
\usepackage[T1]{fontenc} % for robust-looking _ (underscore) characters
\usepackage{xurl}
\newcommand\logic[1]{\textsc{\MakeLowercase{#1}}}
\begin{document}
\noindent
[\dots] then, adding a version counter would turn such policy into 
\begin{center}
\path{ECU_MODEL_2247_v_0} \logic{OR} (\path{CAR_MODEL_21_v_0} 
\logic{AND}  \path{ECU_MODEL_2248_v_0})\,. 
\end{center}
If a key now gets compromised, then the manufacturer updates 
the version of the access policy, which now becomes 
\begin{center}
\path{ECU_MODEL_2247_v_1} \logic{OR} (\path{CAR_MODEL_21_v_1} 
\logic{AND} \path{ECU_MODEL_2248_v_1})\,.
\end{center}
[\dots]
\end{document}
1

Your example does not require math mode, because it does not contain math material. However, in case the expression contains real math material and you need to force a newline inside $...$, you can use \allowbreak.

\documentclass{article}
\begin{document}
[...]then, adding a version counter would turn such policy into
"$ECU\_MODEL\allowbreak
\_2247\_v\_0 \; \textbf{OR} \; \textbf{(}
CAR\_MODEL\_21\_v\_0 \; \textbf{AND} \; ECU\_MODEL\_2248\_v\_0 \textbf{)}$". 
If a key now gets compromised, then the manufacturer updates the version of 
the access policy, that now becomes "$ECU\_MODEL\_2247\_v\_1 \; \textbf{OR} \;
\textbf{(} CAR\_MODEL\allowbreak
\_21\_v\_1 \; \textbf{AND} \;
ECU\_MODEL\_2248\_v\_1 \textbf{)}$"[...]
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.