0

I have a document where I am adding color to various parts using a \newenvironment which was adapted from this answer. While it appears to have worked fine in 430 places, it provided an unexpected result in one case by adding an extra line (2. in the image, below).

While I have ways to get around the problem, maybe there is a fix since I have a lot more work to do on the document, which could cause the problem to move.

Note: I also use the environment inside paragraphs, with no problem. For example: Some words \begin{LII}{more words}\end{LII} end of paragraph.

\documentclass[11pt,letterpaper,oneside,onecolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{parskip}
\renewcommand\familydefault\sfdefault
\usepackage{xcolor}
\newenvironment{LII}{%% https://tex.stackexchange.com/a/207228/187997
    \leavevmode\color{cyan}\ignorespaces%
}{%
}%
\begin{document}
1. Line before, no color.

(2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.

Line after.

2. Line before, color environment above and below paragraph.

\begin{LII}{%
(2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.
}\end{LII}

Line after.

3. Line before, color environment above and below with \% at end of paragraph.

\begin{LII}{%
(2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.%
}\end{LII}

Line after.

4. Line before, color environment within paragraph.

\begin{LII}{(2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.}\end{LII}

Line after.
\end{document}

Example of problem

2
  • you could use \unskip in the end code of your environment, to get rid of the space you added in the first example through the end of line. Feb 4 at 10:24
  • @UlrikeFischer - I was unable to get \unskip to work. As I understand the problem from other posts, color has already started a new line before the \end is reached, so the following line has the color but no text to show it. That means that \unskip cannot remove the empty line. In the absence of a better solution, I will need to do as in example 3 (add %) whenever I add color to one or more paragraphs.
    – Rick Smith
    Feb 4 at 13:44

2 Answers 2

2

your example compile fine for me if I add an unskip:

\documentclass[11pt,letterpaper,oneside,onecolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{parskip}
\renewcommand\familydefault\sfdefault
\usepackage{xcolor}
\newenvironment{LII}{%% https://tex.stackexchange.com/a/207228/187997
    \leavevmode\color{cyan}\ignorespaces%
}{\unskip%
}%
\begin{document}
1. Line before, no color.

(2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.

Line after.

2. Line before, color environment above and below paragraph.

\begin{LII}{%
(2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.
}\end{LII}

Line after.

3. Line before, color environment above and below with \% at end of paragraph.

\begin{LII}{%
(2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.%
}\end{LII}

Line after.

4. Line before, color environment within paragraph.

\begin{LII}{(2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.}\end{LII}

Line after.
\end{document}

enter image description here

1
\documentclass[11pt,letterpaper,oneside,onecolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{parskip}
\renewcommand\familydefault\sfdefault
\usepackage{xcolor}
\newenvironment{LII}{%% https://tex.stackexchange.com/a/207228/187997
    \par\leavevmode\color{cyan}\ignorespaces%
}{%
    \par
}%
\begin{document}
    1. Line before, no color.
    
    (2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.
    
    Line after.
    
    2. Line before, color environment above and below paragraph.
    
    \begin{LII}{%
            (2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.
    }\end{LII}
    
    Line after.
    
    3. Line before, color environment above and below with \% at end of paragraph.
    
    \begin{LII}{%
            (2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.%
    }\end{LII}
    
    Line after.
    
    4. Line before, color environment within paragraph.
    
    \begin{LII}{(2) Identifier-1 must be defined as an alphanumeric data item such that its value can be a program name.}\end{LII}
    
    Line after.
\end{document}

enter image description here

2
  • I appreciate the answer, but I have clarified my use of the environment. It is also used within paragraphs.
    – Rick Smith
    Feb 4 at 2:35
  • I should add that this is an answer to the problem as it was presented. It just isn't quite the answer I need.
    – Rick Smith
    Feb 4 at 2:51

You must log in to answer this question.

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