¿Cómo puedo asignar entidades con nombre HTML a comandos LaTeX?

¿Cómo puedo asignar entidades con nombre HTML a comandos LaTeX?

En concreto me gustaría poder completar esta tabla:

symbol    html entity    LaTeX command
 \deg        °       \begin{alltt}\deg{alltt}

Para tener una entrada para cada entidad con nombre HTML enumerada en elespecificaciones oficiales.

Entiendo que puede que no haya asignaciones para todos ellos, pero cuantos más, mejor.

Necesito esto para comprobar la conformidad de un documento fuente destinado a publicarse tanto en HTML como en LaTeX; Es posible que el documento fuente ya contenga entidades con nombre HTML. Por lo tanto, necesito un cuadro de asignaciones para proporcionar las conversiones o para emitir advertencias de conformidad para aquellas que no se asignan.

Respuesta1

En ConTeXt, el char-ent.luaarchivo contiene la lista de todas las entidades HTML. Puedes acceder a ellos usando la characters.entitiestabla. Por ejemplo, el siguiente código imprime todas las entidades y sus valores en la pantalla.

\starttext
  \startluacode
      local entities = characters.entities
        for name, value in next, entities do
            print(name,value)
        end
  \stopluacode
\stoptext

Las entidades no se traducen al comando TeX correspondiente, sino que se traducen al símbolo Unicode correspondiente. Si desea el nombre TeX correspondiente al símbolo, puede buscar en la characters.datatabla (definida en char-def.lua)

\starttext
  \startluacode
      local data = characters.data
      local function context_name(value)
          value = data[value]
          if value then
              if value.contextname then
                  return value.contextname 
              elseif value.mathname then
                  return value.mathname
              elseif value.mathspec then
                  return value.mathspec[1].name
              else
                return "not defined"
              end
          else
            return "not defined"
          end
      end
      local entities = characters.entities
        for name, value in next, entities do
            print(name,value, context_name(value))
        end
  \stopluacode
\stoptext

La lista resultante esaquí. No sé si LaTeX sigue la misma convención de nomenclatura para todos los comandos.

Respuesta2

Solo para cerrar esto, mi pregunta original era sobre el mapeo de entidades HTML 4.0 a LaTeX. La respuesta de Aditya proporciona la capacidad de mapear una gama mucho más amplia de entidades de personajes con nombre.

He utilizado el conjunto de datos de Aditya para producir las asignaciones solo para HTML 4.0 como se muestra a continuación. Si no está en la lista, no hay mapeo (o he estropeado la reducción del conjunto de datos).

Consulte los comentarios: esta tabla solo tiene mucho valor en ConTeXt.

    HTML 4.0 / LaTeX
    Aacute  /  Aacute
    aacute  /  aacute
    Acirc  /  Acircumflex
    acirc  /  acircumflex
    acute  /  textacute
    AElig  /  AEligature
    aelig  /  aeligature
    Agrave  /  Agrave
    agrave  /  agrave
    alefsym  /  aleph
    Alpha  /  greekAlpha
    alpha  /  greekalpha
    and  /  wedge
    ang  /  angle
    Aring  /  Aring
    aring  /  aring
    asymp  /  approx
    Atilde  /  Atilde
    atilde  /  atilde
    Auml  /  Adiaeresis
    auml  /  adiaeresis
    bdquo  /  quotedblbase
    Beta  /  greekBeta
    beta  /  greekbeta
    brvbar  /  textbrokenbar
    bull  /  textbullet
    cap  /  cap
    Ccedil  /  Ccedilla
    ccedil  /  ccedilla
    cedil  /  textcedilla
    cent  /  textcent
    Chi  /  greekChi
    chi  /  greekchi
    circ  /  textcircumflex
    clubs  /  clubsuit
    cong  /  approxEq
    copy  /  copyright
    crarr  /  carriagereturn
    cup  /  cup
    curren  /  textcurrency
    dagger  /  textdag
    Dagger  /  textddag
    darr  /  downarrow
    dArr  /  Downarrow
    deg  /  textdegree
    Delta  /  greekDelta
    delta  /  greekdelta
    diams  /  blacklozenge
    divide  /  textdiv
    Eacute  /  Eacute
    eacute  /  eacute
    Ecirc  /  Ecircumflex
    ecirc  /  ecircumflex
    Egrave  /  Egrave
    egrave  /  egrave
    empty  /  emptyset
    emsp  /  emspace
    ensp  /  enspace
    Epsilon  /  greekEpsilon
    epsilon  /  greekepsilon
    equiv  /  equiv
    Eta  /  greekEta
    eta  /  greeketa
    ETH  /  Eth
    eth  /  eth
    Euml  /  Ediaeresis
    euml  /  ediaeresis
    exist  /  exists
    fnof  /  fhook
    forall  /  forall
    frac12  /  onehalf
    frac14  /  onequarter
    frac34  /  threequarter
    frasl  /  textfraction
    Gamma  /  greekGamma
    gamma  /  greekgamma
    ge  /  geq
    gt  /  gt
    harr  /  leftrightarrow
    hArr  /  Leftrightarrow
    hellip  /  textellipsis
    Iacute  /  Iacute
    iacute  /  iacute
    Icirc  /  Icircumflex
    icirc  /  icircumflex
    iexcl  /  exclamdown
    Igrave  /  Igrave
    igrave  /  igrave
    image  /  Im
    infin  /  infty
    int  /  intop
    Iota  /  greekIota
    iota  /  greekiota
    iquest  /  questiondown
    isin  /  in
    Iuml  /  Idiaeresis
    iuml  /  idiaeresis
    Kappa  /  greekKappa
    kappa  /  greekkappa
    Lambda  /  greekLambda
    lambda  /  greeklambda
    lang  /  langle
    laquo  /  leftguillemot
    larr  /  leftarrow
    lArr  /  Leftarrow
    lceil  /  lceiling
    ldquo  /  quotedblleft
    le  /  leq
    lfloor  /  lfloor
    lowast  /  ast
    loz  /  lozenge
    lsaquo  /  guilsingleleft
    lsquo  /  quoteleft
    lt  /  lt
    macr  /  textmacron
    mdash  /  emdash
    micro  /  textmu
    middot  /  periodcentered
    Mu  /  greekMu
    mu  /  greekmu
    nbsp  /  nobreakspace
    ndash  /  endash
    ne  /  neq
    ni  /  ni
    not  /  textlognot
    notin  /  nin
    nsub  /  nsubset
    Ntilde  /  Ntilde
    ntilde  /  ntilde
    Nu  /  greekNu
    nu  /  greeknu
    Oacute  /  Oacute
    oacute  /  oacute
    Ocirc  /  Ocircumflex
    ocirc  /  ocircumflex
    OElig  /  OEligature
    oelig  /  oeligature
    Ograve  /  Ograve
    ograve  /  ograve
    Omega  /  greekOmega
    omega  /  greekomega
    Omicron  /  greekOmicron
    omicron  /  greekomicron
    oplus  /  oplus
    or  /  vee
    ordf  /  ordfeminine
    ordm  /  ordmasculine
    Oslash  /  Ostroke
    oslash  /  ostroke
    Otilde  /  Otilde
    otilde  /  otilde
    otimes  /  otimes
    Ouml  /  Odiaeresis
    ouml  /  odiaeresis
    para  /  paragraphmark
    part  /  partial
    permil  /  perthousand
    perp  /  bot
    Phi  /  greekPhi
    phi  /  greekphi
    Pi  /  greekPi
    pi  /  greekpi
    piv  /  greekpialt
    plusmn  /  textpm
    pound  /  textsterling
    prime  /  prime
    Prime  /  doubleprime
    prod  /  prod
    prop  /  propto
    Psi  /  greekPsi
    psi  /  greekpsi
    radic  /  surd
    rang  /  rangle
    raquo  /  rightguillemot
    rarr  /  rightarrow
    rArr  /  Rightarrow
    rceil  /  rceiling
    rdquo  /  quotedblright
    real  /  Re
    reg  /  registered
    rfloor  /  rfloor
    Rho  /  greekRho
    rho  /  greekrho
    rsaquo  /  guilsingleright
    rsquo  /  quoteright
    sbquo  /  quotesinglebase
    Scaron  /  Scaron
    scaron  /  scaron
    sdot  /  cdot
    sect  /  sectionmark
    shy  /  softhyphen
    Sigma  /  greekSigma
    sigma  /  greeksigma
    sigmaf  /  greekfinalsigma
    sim  /  sim
    spades  /  spadesuit
    sub  /  subset
    sube  /  subseteq
    sum  /  sum
    sup  /  supset
    sup1  /  onesuperior
    sup2  /  twosuperior
    sup3  /  threesuperior
    supe  /  supseteq
    szlig  /  ssharp
    Tau  /  greekTau
    tau  /  greektau
    there4  /  therefore
    Theta  /  greekTheta
    theta  /  greektheta
    thetasym  /  greekthetaalt
    thinsp  /  breakablethinspace
    THORN  /  Thorn
    thorn  /  thorn
    tilde  /  texttilde
    times  /  textmultiply
    trade  /  trademark
    Uacute  /  Uacute
    uacute  /  uacute
    uarr  /  uparrow
    uArr  /  Uparrow
    Ucirc  /  Ucircumflex
    ucirc  /  ucircumflex
    Ugrave  /  Ugrave
    ugrave  /  ugrave
    uml  /  textdiaeresis
    Upsilon  /  greekUpsilon
    upsilon  /  greekupsilon
    Uuml  /  Udiaeresis
    uuml  /  udiaeresis
    weierp  /  wp
    Xi  /  greekXi
    xi  /  greekxi
    Yacute  /  Yacute
    yacute  /  yacute
    yen  /  textyen
    yuml  /  ydiaeresis
    Yuml  /  Ydiaeresis
    Zeta  /  greekZeta
    zeta  /  greekzeta
    zwj  /  zwj
    zwnj  /  zwnj

Respuesta3

Hay un gráfico aquí:Entidades de caracteres ISO y sus equivalentes LATEXpor Vidar Bronken Gundersen y Rune Mathisen. El material fuente está aquí:http://www.bitjungle.com/isoent/- Incluye un gran archivo XML con asignaciones entre varios formatos.

La misma gente lo ha convertido en un programa Perl, disponible aquí:http://llg.cubic.org/docs/ent2latex.html(deesta respuestaa¿Cómo buscar un símbolo o identificar un símbolo o carácter matemático?.)

Y aquí hay otra lista:http://www.w3.org/Math/characters/unicode.xml, y los mismos datos compilados en Python:https://gist.github.com/piquadrat/798549

Respuesta4

Algo como esto debería cubrir los casos más comunes.

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{array,booktabs}
\newcommand{\entity}[2]{#1 & \ & \verb}

\begin{document}

\begin{tabular}{l>{\ttfamily}ll}
\toprule
Symbol &\multicolumn{1}{l}{HTML entity} & \LaTeX\ command \\
\midrule
\entity{\'e}{eacute}|\'e| \\
\entity{\TH}{THORN}|\TH| \\
\bottomrule
\end{tabular}

\end{document}

información relacionada