Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm looking for a way to make a new command that makes text on that and only that line red (or in another way clearly distinguishable).

Like the % symbol comments out a line. Are commands that work like that at all possible. I want to make short comments that print and I don't want to have to open and close braces each time.

share|improve this question
    
If you are happy with ending the "line" to be captured by the macro with an empty line you can do \def\bla#1\par{\textcolor{red}{#1}} –  Bordaigorl Jun 12 at 15:10
    
I've always wondered how to do this. It's easy to define a command delimited by a \par or even a blank line directly (leaving a blank line after #1 and the {). But it doesn't work if you want it to work just with that line (even if there is no blank line following). \def\delimitedbyblankline#1 {Something with “#1”}. –  Manuel Jun 12 at 15:38
    
Related: Cool Text Highlighting in LaTeX –  Werner Jun 12 at 16:05
add comment

2 Answers 2

up vote 6 down vote accepted

for this purpose, it is easier to use a "delimited" argument, using \def.

rather than using \par as the delimiter (which will result in a paragraph break, which may not always be wanted), you might choose a single non-% character that won't appear in your comment text. if | is such a character, this should work:

\def\bla#1|{\textcolor{red}{#1}}

this approach should work even if \bla doesn't begin a new line, and the whole comment is embedded in a block of text.

(@Bordaigorl had the right idea in a comment, but \par may be too limiting.)

some additional commentary on this approach is given in the answer to this question: \renewcommand for commands defined with \def.

share|improve this answer
1  
\par wouldn't make a paragraph break if it was being used as an argument delimiter, but why not use \textcolor directly rather than a delimited argument at all? –  David Carlisle Jun 12 at 15:27
add comment

The macro \HighlightRestOfCurrentLine below allows you to highlight to the end of the current line:

enter image description here

References:

Notes:

  • This does require two runs. First one to determine the locations, and the second to do the drawing. Although I have a feeling this should be doable in just one run.

  • The magic numbers for determing the edge of the page are obtained by using \layout from the layout package.

  • The \tikzmark is from Adding a large brace next to a body of text.

Code:

\documentclass{article}
%\usepackage{layout}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[baseline] (#1) {};}

\newcommand{\HighlightRestOfCurrentLine}[1][]{%
    \tikzmark{Start}%
    \begin{tikzpicture}[overlay,remember picture]
        \coordinate (EdgeOfText) at ($(current page.west |- 0,0) + (1.0in+\hoffset+\oddsidemargin+\textwidth,0.3ex) + (0.1em,1.6ex)$) ;
        \draw [draw=none,fill=green!50, #1]  ($(Start)+(0,-0.6ex)$) rectangle (EdgeOfText);
    \end{tikzpicture}
}%

\begin{document}%\layout
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at dignissim eros. 
 Morbi faucibus sit amet felis a accumsan. \HighlightRestOfCurrentLine Aliquam 
 dapibus pellentesque dui, vitae aliquam turpis semper eget. 
 Donec egestas leo nibh, at malesuada leo congue non. 
 Cras laoreet lectus sed tortor laoreet, ac aliquet nibh condimentum. 
 Nam elementum ante non nunc facilisis porttitor. Nullam non suscipit lorem. 
 Sed arcu dui, accumsan et pretium dictum, venenatis id metus.

Mauris massa lacus, vehicula 
vitae \HighlightRestOfCurrentLine[fill=none,draw=gray, ultra thick] blandit ac, 
fermentum vitae ligula. Maecenas ultricies, tortor a sodales ullamcorper, 
erat lorem semper leo, vel pretium felis arcu ut velit. Aenean viverra 
lacus at nisi malesuada luctus. Maecenas libero odio, luctus et blandit 
vitae, commodo in turpis. Duis nisi enim, gravida id libero id, 
sollicitudin volutpat purus. Curabitur rhoncus risus euismod arcu venenatis, 
\HighlightRestOfCurrentLine[red!25]non elementum mi lobortis. 
Pellentesque quis leo eu nunc malesuada condimentum. Ut dictum iaculis 
aliquam. Nunc tincidunt a ligula in adipiscing. Praesent 
\HighlightRestOfCurrentLine[fill=none,draw=blue, dotted, ultra thick]ultricies sem 
odio, eget pellentesque mi faucibus vitae. Class aptent taciti sociosqu 
ad litora torquent per conubia nostra, per inceptos himenaeos. 
Sed ullamcorper massa risus, non commodo dolor eleifend quis. 
Mauris ultrices lorem a orci hendrerit tempor. Sed fringilla mattis fringilla. 
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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