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 have a tex file which is like this :

  \cleardoublepage
    \phantomsection
    \includepdf[pages=-,addtotoc={ 1,section,1, 200_project_title: , p1,
        1,subsection,1,Section A - Project Identification, p2,
        1,subsection,1,Section C - Basic or Applied Research,p3,
        3,subsection,1,Section D - Additional project information,p4
        }]{fixed_2010_2.pdf}

pdflatex fails to compile wherever there is undercore in section title

e.g  200_project_title:

It would be great if someone help me fine out a better way to pass section title without escaping those underscore and possibility handling other special characters which might mess up with compilation

thanks

EDIT: using \begingroup \catcode'\_=12 \tableofcontents \endgroup screenshot

EDIT: using in preamble : \usepackage[T1]{fontenc} and for table of contents \begingroup \catcode'\_=12 \tableofcontents \endgroup

screenshot 2

Working one after you kind suggestions and answers: This working now for me (do not know any hazards yet) thank you for all your suggestions:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\usepackage[
  pdfpagelabels=true,
  pdftitle={Report Title},
  pdfauthor={sakhunzai},
]{hyperref}
\usepackage[T1]{fontenc}

\hypersetup{
    colorlinks=true, 
        linkcolor=blue
}

\begin{document}
\catcode`\_=12

\cleardoublepage
\pdfbookmark{\contentsname}{toc}
\pagenumbering{roman}
\tableofcontents 

\cleardoublepage
\phantomsection
\includepdf[pages=-,addtotoc={ 1,section,1, 200_project_title: , p1,
        1,subsection,1,Section A - Project Identification, p2,
        1,subsection,1,Section C - Basic or Applied Research,p3,
        3,subsection,1,Section D - Additional project information,p4
        }]{fixed_2010_2.pdf}
 \end{document}
share|improve this question
    
Without a MWE this is untested but if you don't have any underscores in math in section titles you can probably go \begingroup \catcode'\_=12 \tableofcontents \endgroup so _ is a normal character while the toc file is being processed. (with a backtick not ' but I can't remember how to get that in this chat) –  David Carlisle Nov 15 '12 at 11:30
    
@DavidCarlisle , thanks for your comments ,it fixed the issue partially e.g now I see a dot in place of underscore –  sakhunzai Nov 15 '12 at 11:47
    
@DavidCarlisle Use two backquotes to delimit a code that contains backquotes: \begingroup\catcode`\_=12 \tableofcontents\endgroup. Another way would be to write 200\_project\_title: (which would work also with OT1 encoded fonts). –  egreg Nov 15 '12 at 11:50
    
I just added \begin{document}\catcode_=12` and rest of script , its working bookmarks look great but the Content area showing a dot , please check the attachedscreen shot , thanks for your direction –  sakhunzai Nov 15 '12 at 11:58
    
@sakhunzai you probably need to use a font encoding that has underscores in the underscpre position use \usepackage[T1]{fontenc} –  David Carlisle Nov 15 '12 at 11:58

1 Answer 1

up vote 4 down vote accepted

If you want to avoid using \_ for underscore you need to make it an ordinary character and use a font encoding that supports it so add

 \usepackage[T1]{fontenc}

to the preamble and then include the table of contents file the includes underscores with

\begingroup \catcode'\_=12 \tableofcontents \endgroup 

If for some reason you are committed to OT1 fonts and still want to avoid quoting _ then you could instead use

\begingroup \catcode'\_=13 \def_{\_} \tableofcontents \endgroup 
share|improve this answer
    
thanks @David Carlisle , first case works but removes underscore, please check the second attachment in question –  sakhunzai Nov 15 '12 at 12:14
    
I have accepted your ans. , plz check my edits if you have any further suggests regarding my working code.thanks –  sakhunzai Nov 15 '12 at 12:40
    
looks OK except that you globally redefined _ to be an ordinary character (as opposed to just locally while the toc is read) which is OK so long as you don't need it for a math subscript anywhere (you can still get math subscripts using \sb) –  David Carlisle Nov 15 '12 at 12:51
    
thanks @David Carlisle for sharing your knowledge :) –  sakhunzai Nov 15 '12 at 12:58

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.