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 set up a \newenvironment, some texts in this environment exceed the text width, but this doesn't happen always. The following is the \newenvironment setup

% is used for parameters within a detailed function description
\newenvironment{DoxyParamCaption}{%
   \renewcommand{\item}[2][]{##1 {\em ##2}}%
}{%
}

\subsubsection[{j1939\_\-initialize\_\-stack}]{\setlength{\rightskip}%
{0pt   plus 5cm}void j1939\_\-initialize\_\-stack (
\begin{DoxyParamCaption}
\item[{{\bf j1939\_\-stack\_\-id\_\-t}}]{stack\_\-id, }
\item[{{\bf ProtocolRXTablePtr}}]{rx\_\-table\_\-ptr, }
\item[{{\bf J1939TransmitMessagePtr}}]{tx\_\-table\_\-ptr, }
\item[{{\bf uint16}}]{tx\_\-table\_\-size, }
\item[{{\bf uchar8} $\ast$}]{rx\_\-buff, }
\item[{{\bf uint16}}]{rx\_\-buff\_\-size}
\end{DoxyParamCaption}
)}}

The result will be like as follows

enter image description here

As you can see, the function's head goes into the right margin of the paper. But some other examples works fine. See another one in the same environment as follows

enter image description here

I don't why this happens. Could anyone tell me how to fix this? Thank you very very much.

share|improve this question
    
You shouldn't use the old LaTeX2.0 style formatting macros like \bf or \it any longer. Use bfseries instead. See e.g. Does it matter if I use \textit or \it for more details. –  Martin Scharrer Jul 29 '11 at 20:13

2 Answers 2

up vote 4 down vote accepted

Although you explicitly state the hyphenations of the variables (via \-), you leave the variable types (typeset using {\bf ...}) as is. This is a problem, since LaTeX does not know where these "words" need to be hyphenated at the end of a line. This is also evident from LaTeX's attempt to hyphenate DataWidth as DataW\-idth in your second example; something that is obviously wrong.

One solution might be impose a \raggedright formatting in the \subsubsection{...} definition that would allow words to be wrapped (instead of hyphenated) at the end of \linewidth:

\subsubsection[{j1939\_\-initialize\_\-stack}]{\raggedright%
  void j1939\_\-initialize\_\-stack (
  \begin{DoxyParamCaption}
    \item[{{\bf j1939\_\-stack\_\-id\_\-t}}]{stack\_\-id, }
    \item[{{\bf ProtocolRXTablePtr}}]{rx\_\-table\_\-ptr, }
    \item[{{\bf J1939TransmitMessagePtr}}]{tx\_\-table\_\-ptr, }
    \item[{{\bf uint16}}]{tx\_\-table\_\-size, }
    \item[{{\bf uchar8} $\ast$}]{rx\_\-buff, }
    \item[{{\bf uint16}}]{rx\_\-buff\_\-size}
  \end{DoxyParamCaption}
)}

However, this actually makes the use of manual hyphenation unnecessary. Regardless, some cleanup is also encouraged in the code:

  • As suggested by l2tabu, the use of {\bf ...} is considered obsolete. Rather use \textbf{...} for local font changes, or {\bfseries ...} for global font changes.
  • There's no need for double-nesting the descriptor field of \item[...]. It would suffice to have \item[\textbf{uint16}]{rx\_\-buff\_\-size}.
  • Edit: The redefinition of \item does not require using ##1 and ##2; so change it to #1 and #2. Not sure whether this is possible, since your document may contain other uses and/or redefinitions, so you're keeping it this way for consistency.
  • You could include the boldface font change for the variable type in the redefinition of \item.

Using the above suggestions your code example could be simplified to

% is used for parameters within a detailed function description
\newenvironment{DoxyParamCaption}{%
   \renewcommand{\item}[2][]{\textbf{##1} {\normalfont\em ##2}}%
}{%
}

\subsubsection[j1939\_initialize\_stack]{\raggedright%
  void j1939\_initialize\_stack (
  \begin{DoxyParamCaption}
    \item[j1939\_stack\_id\_t]{stack\_id, }
    \item[ProtocolRXTablePtr]{rx\_table\_ptr, }
    \item[J1939TransmitMessagePtr]{tx\_table\_ptr, }
    \item[uint16]{tx\_table\_size, }
    \item[uchar8 $\ast$]{rx\_buff, }
    \item[uint16]{rx\_buff\_size}
  \end{DoxyParamCaption})}

which is a little easier to read. Since the scope/extent of the use is not clearly specified, defining a more solid definition of \subsubsection to automatically perform a \raggedright justification via (say) titlesec was not implemented.

share|improve this answer
    
For defining \subsubsection via titlesec package, using \filright works. Thanks for your help. –  Jason Xu Aug 2 '11 at 12:53

The MWE example and method you are trying to use to format text is very complicated and will lead to a lot of errors while you typing in the information.

Firstly, I would use the underscore package to provide the underscores (eliminating \_). If words are mixed with non-characters, TeX will not hyphenate words such as,

   J1939TransmitMessagePtr

is not hyphenated.

\documentclass{article}
\usepackage{underscore}
\makeatletter
 \def\pointer#1{\@tfor\next:=#1\do{\next\-}}
 \makeatother
\begin{document}
\hsize1in
\subsubsection[{j1939_initialize_stack}]{%
    stack_id, {\bf  J1939Transmit\-MessagePtr} 
 }
 % autohyphenate pointer
 \pointer{J1939TransmitMessagePtr}
\end{document}

In the example I have left \bf as you did to demonstrate that it is not the cause of the error. You should change it to \bfseries'.

My own preference is to define individual macros as I have done for pointer, introduce the optional hyphen or replace \- with hskip0pt if you don't want the hyphen to show up, as it is sometimes confusing in computer code.

share|improve this answer

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.