2

I've just discovered kvoptions package to pass options to my sty file. I want to pass the title of the document but it contains Spanish characters (á,é,í,ó,ú) and it can't be rendered well. I use this characters perfect in my document, but no with \style@variable command. How can I use it? I'm a newbie with LaTeX. This is the document

\documentclass[a4paper, 11pt]{article}
\usepackage[titulo={Práctica 1: Búsquedas con trayectorias simples}]{estilo}

 \begin{document}
   \maketitle 

 \end{document}

This is the estilo.sty file.

\ProvidesPackage{estilo}

%Comandos para configurar el idioma
\usepackage[spanish,activeacute]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} %Necesario para el uso de las comillas latinas.
\usepackage{geometry} % Used to adjust the document margins

%Package for options management
\RequirePackage{kvoptions}
\DeclareStringOption[MetaHeuristicas]{titulo}
\ProcessKeyvalOptions*

%Importante que esta sea la última órden del preámbulo
\usepackage{hyperref}
   \hypersetup{
     pdftitle=\estilo@titulo,
     pdfauthor={Me},
     unicode,
     breaklinks=true,  % so long urls are correctly broken across lines
     colorlinks=true,
     urlcolor=blue,
     linkcolor=darkorange,
     citecolor=darkgreen
     }

Output

Output

EDIT: If I load [utf8]{inputenc} before loading estilo.sty, I get this

Output2

2
  • You should, at the least, have \usepackage[utf8]{inputenc} before loading estilo
    – egreg
    Apr 4, 2016 at 16:31
  • If I do that I get this imgur.com/5y9gluI . It's better but it's no readable :(. Thank you. Apr 4, 2016 at 16:37

2 Answers 2

2

The package options of \usepackage are first read by LaTeX:

  • The 8-bit bytes of the input file have category code 12 (other) like digits. \usepackage[utf8]{inputenc} makes these bytes active. The active character bytes then decode the bytes to get the macros for the Unicode character representation.

  • LaTeX expands the options the hard way (\edef) assuming options are only simple ASCII letters and digits. Package kvoptions-patch patches the LaTeX option parsing to support arbitrary macros in the values of key value settings without expanding them.

The document start now looks like:

\documentclass[a4paper, 11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{kvoptions-patch}
\usepackage[titulo={Práctica 1: Búsquedas con trayectorias simples}]{estilo}

(If kvoptions-patch is loaded before \documentclass via \RequirePackage{kvoptions-patch}, then macros can also be used in option values for global options.)

Result

A more robust interface regarding the option processing is to use a macro after the package is loaded, e.g.:

\usepackage{estilo}
\estilosetup{titulo={...}}
1
  • It works like a charm. One Line Solution :D!!! Thank you. Apr 4, 2016 at 17:02
2

When the option to estilo is read in, the package inputenc has not yet been loaded. You can fix the string by using \scantokens

estilo.sty

\ProvidesPackage{estilo}

%Comandos para configurar el idioma
\usepackage[T1]{fontenc} %Necesario para el uso de las comillas latinas.
\usepackage[utf8]{inputenc}
\usepackage[spanish,activeacute]{babel}
\usepackage{geometry} % Used to adjust the document margins

%Package for options management
\RequirePackage{kvoptions}
\DeclareStringOption[MetaHeuristicas]{titulo}
\ProcessKeyvalOptions*

\@ifundefined{estilo@titulo}{}{%
  \scantokens\expandafter{\expandafter\def\expandafter\estilo@titulo\expandafter{\estilo@titulo}}%
}

%Importante que esta sea la última órden del preámbulo
\usepackage{hyperref}
\hypersetup{
   pdftitle=\estilo@titulo,
   pdfauthor={Me},
   unicode,
   breaklinks=true,  % so long urls are correctly broken across lines
   colorlinks=true,
   urlcolor=blue,
   linkcolor=darkorange,
   citecolor=darkgreen
}

test.tex

\documentclass[a4paper, 11pt]{article}
\usepackage[titulo={Práctica 1: Búsquedas con trayectorias simples}]{estilo}

\begin{document}
\maketitle

\end{document}

Info window

enter image description here

Output of pdfinfo

> pdfinfo -enc UTF-8 test.pdf
Title:          Práctica 1: Búsquedas con trayectorias simples
Subject:        
Keywords:       
Author:         Me
Creator:        LaTeX with hyperref package
Producer:       pdfTeX-1.40.16
CreationDate:   Mon Apr  4 18:45:39 2016
ModDate:        Mon Apr  4 18:45:39 2016
Tagged:         no
Form:           none
Pages:          1
Encrypted:      no
Page size:      595.276 x 841.89 pts (A4) (rotated 0 degrees)
File size:      36484 bytes
Optimized:      no
PDF version:    1.5
1
  • Thank you too, but the other solution works perfect for me :D! Apr 4, 2016 at 17:02

You must log in to answer this question.

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