Pacchetto Macchine di Turing Vs Hyperref e Listings

  • Creatore
    Topic
  • #64333
    Up
    0
    Down
    ::


    Ciao a tutti, avevo bisogno di scrivere delle macchine di Turing a nastro e ho cercato un po’ trovando il pacchetto che allego. Tutto ok facendo partire il suo esempio ma nel mio codice non funziona. Provo a fare emc e scopro che il problema è l’hyperref. Ora…io di pacchetti non so nulla né di hyperref 🙂 qualcuno potrebbe aiutarmi e dirmi come poter sistemare le cose?
    ps commentato nel codice c’è il geometry originale del pacchetto ma io ho lasciato il layaureo perché uso quello.
    Ho lasciato tutte le ipostazioni di formattazione perché credo potrebbero essere importanti.
    A riguardo del listings c’è invece un’altro problema e cioé, anche togliendo l’hyperref, e quindi facendo in modo che il pacchetto turing funzioni correttamente, mi stampa tutto ok più una riga di codice vuota e sfasata all’inizio che non riesco a togliere (e mi impedisce di fare i riquadri che verrebbero orribili), questo è un problema secondario perché ho risolto facendo partire la numerazione da zero, togliendo il riquadro e bon il risultato è almeno accettabile..se però oltre a scoprire come fare per poterlo usare (con hyperref) qualcuno riesce anche a togliere quella righina fastidiosa…super!!
    p.s la mdt riportata è quella dell’esempio del pacchetto originale e genera circa 3 pagine, inoltre segnalo che l’originale usa l’article ma io uso il report (però senza hyperref funziona comunque bene lostesso).
    Grazie a tutti e spero che questo pacchetto possa anche essere utile a qualcun’altro!

    …cavolo visto che non arrivo ad allegare il file .sty (qualcuno sa perhè mi dice non trovato sia che faccia aggiungi file sia che lo trascini dentro la finestra?!) lo riporto come codice completo quì sotto!!

    `\documentclass[12pt,
    a4paper,twoside,openright, %openright per capitoli sempre a dx;
    notitlepage,
    fleqn ,
    ]{report}

    \usepackage[T1]{fontenc}
    \usepackage[applemac]{inputenc}
    \usepackage[english,italian]{babel}

    \usepackage[binding=5mm]{layaureo}

    %\usepackage[colorlinks,hyperindex,linkcolor=black,citecolor=black,bookmarks=false,hyperfootnotes=true]{hyperref}
    %\hypersetup{
    % pdftitle={Emc MdT},
    % pdfauthor={Memmedesimo},
    % pdfsubject={Problemi hyperref-VS-pacchettoMdT}
    % pdfkeywords={problemi, MdT, Hyperreff}}

    \usepackage{listings}
    \lstset{numbers=left,,basicstyle=\small\ttfamily,frameround=fttt,escapeinside={&!}{!&}}

    \usepackage{turing}
    %\usepackage{geometry}
    %\geometry{textwidth=170mm,textheight=250mm}

    \begin{document}

    \newtm(1,0,1,1,0,1,0,1,\#,1,0,1,1,0,1)
    \turingrules{%
    (next,0,next,0,R),%
    (next,1,next,1,R),%
    (next,0',next,0',R),%
    (next,1',next,1',R),%
    (next,\#,next,\#,R),%
    (next,-,check,-,L),%
    %
    (check,0,prepadd0,-,L),%
    (check,1,prepadd1,-,L),%
    (check,\#,cleanup,-,L),%
    %
    (prepadd0,0,prepadd0,0,L),%
    (prepadd0,1,prepadd0,1,L),%
    (prepadd0,\#,add0,\#,L),%
    (add0,0',add0,0',L),%
    (add0,1',add0,1',L),%
    (add0,-,next,0',R),%
    (add0,0,next,0',R),%
    (add0,1,next,1',R),%
    %
    (prepadd1,0,prepadd1,0,L),%
    (prepadd1,1,prepadd1,1,L),%
    (prepadd1,\#,add1,\#,L),%
    (add1,0',add1,0',L),%
    (add1,1',add1,1',L),%
    (add1,0,next,1',R),%
    (add1,1,propadd1,0',L),%
    (add1,-,next,1',R),%
    (propadd1,0,next,1,R),%
    (propadd1,1,propadd1,0,L),%
    (propadd1,-,next,1,R),%
    %
    (cleanup,0,cleanup,0,L),%
    (cleanup,1,cleanup,1,L),%
    (cleanup,0',cleanup,0,L),%
    (cleanup,1',cleanup,1,L),%
    (cleanup,-,stop,-,H)%
    }
    \begin{lstlisting}[firstnumber=0,caption=ciccio]
    &!
    \showtm
    \runtm
    !&
    \end{lstlisting}
    \end{document}`

    `%=============================================================================
    % Turing — (turing.sty) Style file
    % A LaTeX class for defining and using Turing machines.
    % Author: Mark Schaefer (mark.schaefer@informatik.uni-augsburg.de)
    % University of Augsburg, Germany
    %
    % Copyright (c) 2006 Mark Schaefer
    % All rights reserved.
    %
    % Permission is hereby granted, without written agreement and without
    % license or royalty fees, to use, copy, modify, and distribute this
    % software and its documentation for any purpose, provided that the
    % above copyright notice and the following two paragraphs appear in
    % all copies of this software.
    %
    % IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
    % SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
    % THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED
    % OF THE POSSIBILITY OF SUCH DAMAGE.
    %
    % THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES,
    % INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    % AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
    % ON AN “AS IS” BASIS, AND THE AUTHOR HAS NO OBLIGATION TO
    % PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
    %
    %==============================================================================
    % This package allows the definition, simulation and graphical display of
    % deterministic Turing machines. For the time being this manual assumes that
    % the reader is familiar with this concept.
    %
    % One can initialise a new Turing machine by \newtm(band content).
    % The band entries have to be separated by a ',', after the rightmost entry,
    % no ',' is allowed. start and stop denote states of the Turing machine
    % (obviously, THE start and THE stop state). In general states and band entries
    % can be arbitrary strings, where '-' is used as blank, special characters have
    % to be escaped, e.g. as \# Don't use '=' for states or entries.
    %
    % For example: \newtm(-,1,0,1,0,\#,1,0,1,-)
    %
    % The next-state function is defined by \turingrules{rule1,rule2,…,ruleN}, as
    % for the band entries, rules are separated by ',' and again after the last
    % rule, no ',' is allowed. % Rules have the form
    % (old_state, current_entry, new_state, new_entry, (L|H|R)}.
    %
    % For example: \turingrules{(q0,0,q0,1,R),(q0,1,q0,0,R),(q0,-,stop,-,H)}
    %
    % Note that the next-state function does not have to be complete; an error
    % message is generated if an entry is not found while the old state of the
    % Turing machine is preserved.
    %
    % A graphical representation is generated by \showtm, the following state is
    % generated by \nextstep. Once, the stop-state is reached, \nextstep will have
    % no effect.
    %
    % For convenience, there are the following three commands:
    %
    % – \stepandshow : makes a step and shows the next state, this is repeated times,
    % e.g. \stepandshow{100}
    % – \loopstep
    : same as \stepandshow, but the intermediate results are not printed
    %
    % – \runtm : same as \stepandshow, but the Turing machine stops automatically, if
    % the stop state was reached
    % Caution! The Turing machine may run forever, and so will latex.
    %
    % Have a look at the output of TeX, error messages will be reported there.
    %==============================================================================

    \NeedsTeXFormat{LaTeX2e}[1995/12/01]
    \ProvidesPackage{turing}[2006/02/17]
    \message{This is Turing-Tex.}

    \def\newworld{=}
    \def\blank{-}

    \def\newtm<#1,#2>(#3){
    \xdef\tm{(=,)(#1)(#3,=,)}
    \xdef\stopstate{#2}
    \xdef\stopreached{no}
    }

    \def\turingrules#1{
    \xdef\rules{#1,(,,,,),}
    }

    \def\findstate(#1,#2)(#3)(#4,#5,#6);{
    \xdef\farleft{#2}
    \xdef\left{#1}
    \xdef\state{#3}
    \xdef\value{#4}
    \xdef\right{#5}
    \xdef\farright{#6}
    }

    \newif\ifnorulegiven
    \newif\ifnorulefound

    \def\findrule{
    \norulegivenfalse
    \norulefoundtrue
    \xdef\remrules{\rules}
    \loop
    \expandafter\findr\remrules;
    \ifnorulefound
    \repeat
    }

    \def\findr(#1,#2,#3,#4,#5),#6;{
    \edef\stpe{#1}
    \edef\stpv{#2}
    \ifx\state\stpe
    \ifx\value\stpv
    \norulefoundfalse
    \xdef\newstate{#3}
    \xdef\newvalue{#4}
    \xdef\direction{#5}
    \fi
    \fi

    \xdef\remrules{#6}
    \ifx\empty\remrules
    \norulefoundfalse
    \norulegiventrue
    \fi
    }

    \def\nextstep{
    \expandafter\findstate\tm;
    \findrule

    \ifx\newstate\stopstate\xdef\stopreached{yes}\fi

    \ifnorulegiven
    \ifx\state\stopstate
    \message{Turing machine reached stop state.}
    \else
    \message{Rule not found for (state,value) (\state,\value)}
    \fi
    \else
    \def\leftm{L}
    \def\rightm{R}
    \def\middlem{H}

    \if\direction\leftm
    \if\left\newworld
    \xdef\tm{(=,\farleft)(\newstate)(-,\newvalue,\right,\farright)}
    \else
    \xdef\tm{(\farleft)(\newstate)(\left,\newvalue,\right,\farright)}
    \fi
    \else\if\direction\rightm
    \if\right\newworld
    \xdef\tm{(\newvalue,\left,\farleft)(\newstate)(-,=,\farright)}
    \else
    \xdef\tm{(\newvalue,\left,\farleft)(\newstate)(\right,\farright)}
    \fi
    \else\if\direction\middlem
    \xdef\tm{(\left,\farleft)(\newstate)(\newvalue,\right,\farright)}
    \fi\fi\fi

    \fi
    }

    \def\spec#1{\vbox{\hbox to 1em {\vrule height0.1em depth0.2em\hfill#1\hfill{}\vrule height0.1em}\hrule}}
    \def\speca#1{\vbox{\hrule\hbox to 1em {\vrule height0.8em depth0.2em\hfill#1\hfill{}\vrule height0.8em}\hrule}}

    \newif\iftmfull
    \newif\ifnextvalue

    \def\showtm{
    \xdef\result{}

    \expandafter\findstate\tm;

    \tmfulltrue
    \edef\remtm{\left,\farleft}
    \loop
    \expandafter\mkleft\remtm;
    \iftmfull
    \repeat

    \if\value\blank
    \xdef\result{\result\speca{}\ }
    \else
    \xdef\result{\result\speca{\value}\ }
    \fi

    \tmfulltrue
    \edef\remtm{\right,\farright}
    \loop
    \expandafter\mkright\remtm;
    \iftmfull
    \repeat

    \mbox{}\result\hskip3em(\state)
    }

    \def\mkleft#1,#2;{
    \edef\next{#1}
    \if\next\newworld
    \xdef\result{\spec{}\ \result}
    \else\if\next\blank
    \xdef\result{\result\spec{}\ }
    \else
    \xdef\result{\spec{#1}\ \result}
    \fi\fi
    \edef\remtm{#2}
    \ifx\empty\remtm
    \tmfullfalse
    \fi
    }

    \def\mkright#1,#2;{
    \edef\next{#1}
    \if\next\newworld
    \xdef\result{\result\spec{}\ }
    \else\if\next\blank
    \xdef\result{\result\spec{}\ }
    \else
    \xdef\result{\result\spec{#1}\ }
    \fi\fi
    \edef\remtm{#2}
    \ifx\empty\remtm
    \tmfullfalse
    \fi
    }

    \def\stepandshow#1{%
    \newcount\tmit
    \tmit=#1
    \loop
    {\nextstep\showtm}
    \advance\tmit by -1
    \ifnum\tmit>0
    \repeat
    }

    \def\runtm{%
    \loop
    {\nextstep\showtm}
    \def\next{no}
    \ifx\next\stopreached
    \repeat
    }

    \def\loopstep#1{%
    \newcount\tmit
    \tmit=#1
    \loop
    {\nextstep}
    \advance\tmit by -1
    \ifnum\tmit>0
    \repeat
    }

    \endinput`

Visualizzazione 9 filoni di risposte
  • Autore
    Risposte
    • #64334
      Up
      0
      Down
      ::


      Errore drammatico commesso dagli autori del pacchetto: ridefinire \value.

      Cambia tutti i \value in \Value e, già che ci sei, \left in \Left e \right in \Right. Ahimè, è scritto con i piedi.

      Meglio ancora, sostituisci con
      `%=============================================================================
      % Turing — (turing.sty) Style file
      % A LaTeX class for defining and using Turing machines.
      % Author: Mark Schaefer (mark.schaefer@informatik.uni-augsburg.de)
      % University of Augsburg, Germany
      %
      % Copyright (c) 2006 Mark Schaefer
      % All rights reserved.
      %
      % Permission is hereby granted, without written agreement and without
      % license or royalty fees, to use, copy, modify, and distribute this
      % software and its documentation for any purpose, provided that the
      % above copyright notice and the following two paragraphs appear in
      % all copies of this software.
      %
      % IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
      % SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
      % THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED
      % OF THE POSSIBILITY OF SUCH DAMAGE.
      %
      % THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES,
      % INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      % AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
      % ON AN “AS IS” BASIS, AND THE AUTHOR HAS NO OBLIGATION TO
      % PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
      %
      %==============================================================================
      % This package allows the definition, simulation and graphical display of
      % deterministic Turing machines. For the time being this manual assumes that
      % the reader is familiar with this concept.
      %
      % One can initialise a new Turing machine by \newtm(band content).
      % The band entries have to be separated by a ',', after the rightmost entry,
      % no ',' is allowed. start and stop denote states of the Turing machine
      % (obviously, THE start and THE stop state). In general states and band entries
      % can be arbitrary strings, where '-' is used as blank, special characters have
      % to be escaped, e.g. as \# Don't use '=' for states or entries.
      %
      % For example: \newtm(-,1,0,1,0,\#,1,0,1,-)
      %
      % The next-state function is defined by \turingrules{rule1,rule2,…,ruleN}, as
      % for the band entries, rules are separated by ',' and again after the last
      % rule, no ',' is allowed. % Rules have the form
      % (old_state, current_entry, new_state, new_entry, (L|H|R)}.
      %
      % For example: \turingrules{(q0,0,q0,1,R),(q0,1,q0,0,R),(q0,-,stop,-,H)}
      %
      % Note that the next-state function does not have to be complete; an error
      % message is generated if an entry is not found while the old state of the
      % Turing machine is preserved.
      %
      % A graphical representation is generated by \showtm, the following state is
      % generated by \nextstep. Once, the stop-state is reached, \nextstep will have
      % no effect.
      %
      % For convenience, there are the following three commands:
      %
      % – \stepandshow : makes a step and shows the next state, this is repeated times,
      % e.g. \stepandshow{100}
      % – \loopstep
      : same as \stepandshow, but the intermediate results are not printed
      %
      % – \runtm : same as \stepandshow, but the Turing machine stops automatically, if
      % the stop state was reached
      % Caution! The Turing machine may run forever, and so will latex.
      %
      % Have a look at the output of TeX, error messages will be reported there.
      %==============================================================================

      \NeedsTeXFormat{LaTeX2e}[1995/12/01]
      \ProvidesPackage{turing}[2006/02/17]
      \message{This is Turing-Tex.}

      \def\tm@newworld{=}
      \def\tm@blank{-}

      \def\newtm<#1,#2>(#3){
      \xdef\tm@tm{(=,)(#1)(#3,=,)}
      \xdef\tm@stopstate{#2}
      \xdef\tm@stopreached{no}
      }

      \def\turingrules#1{
      \xdef\tm@rules{#1,(,,,,),}
      }

      \def\tm@findstate(#1,#2)(#3)(#4,#5,#6);{
      \xdef\tm@farleft{#2}
      \xdef\tm@left{#1}
      \xdef\tm@state{#3}
      \xdef\tm@value{#4}
      \xdef\tm@right{#5}
      \xdef\tm@farright{#6}
      }

      \newif\iftm@norulegiven
      \newif\iftm@norulefound

      \def\tm@findrule{
      \tm@norulegivenfalse
      \tm@norulefoundtrue
      \xdef\tm@remrules{\tm@rules}
      \loop
      \expandafter\tm@findr\tm@remrules;
      \iftm@norulefound
      \repeat
      }

      \def\tm@findr(#1,#2,#3,#4,#5),#6;{
      \edef\tm@stpe{#1}
      \edef\tm@stpv{#2}
      \ifx\tm@state\tm@stpe
      \ifx\tm@value\tm@stpv
      \tm@norulefoundfalse
      \xdef\tm@newstate{#3}
      \xdef\tm@newvalue{#4}
      \xdef\tm@direction{#5}
      \fi
      \fi

      \xdef\tm@remrules{#6}
      \ifx\@empty\tm@remrules
      \tm@norulefoundfalse
      \tm@norulegiventrue
      \fi
      }

      \def\tm@nextstep{
      \expandafter\tm@findstate\tm@tm;
      \tm@findrule

      \ifx\tm@newstate\tm@stopstate\xdef\tm@stopreached{yes}\fi

      \iftm@norulegiven
      \ifx\tm@state\tm@stopstate
      \message{Turing machine reached stop state.}
      \else
      \message{Rule not found for (state,value) (\tm@state,\tm@value)}
      \fi
      \else
      \def\tm@leftm{L}
      \def\tm@rightm{R}
      \def\tm@middlem{H}

      \if\tm@direction\tm@leftm
      \if\tm@left\tm@newworld
      \xdef\tm@tm{(=,\tm@farleft)(\tm@newstate)(-,\tm@newvalue,\tm@right,\tm@farright)}
      \else
      \xdef\tm@tm{(\tm@farleft)(\tm@newstate)(\tm@left,\tm@newvalue,\tm@right,\tm@farright)}
      \fi
      \else\if\tm@direction\tm@rightm
      \if\tm@right\tm@newworld
      \xdef\tm@tm{(\tm@newvalue,\tm@left,\tm@farleft)(\tm@newstate)(-,=,\tm@farright)}
      \else
      \xdef\tm@tm{(\tm@newvalue,\tm@left,\tm@farleft)(\tm@newstate)(\tm@right,\tm@farright)}
      \fi
      \else\if\tm@direction\tm@middlem
      \xdef\tm@tm{(\tm@left,\tm@farleft)(\tm@newstate)(\tm@newvalue,\tm@right,\tm@farright)}
      \fi\fi\fi

      \fi
      }

      \def\tm@spec#1{\vbox{\hbox to 1em {\vrule height0.1em depth0.2em\hfill#1\hfill{}\vrule height0.1em}\hrule}}
      \def\tm@speca#1{\vbox{\hrule\hbox to 1em {\vrule height0.8em depth0.2em\hfill#1\hfill{}\vrule height0.8em}\hrule}}

      \newif\iftm@tmfull
      \newif\iftm@nextvalue

      \def\showtm{
      \xdef\tm@result{}

      \expandafter\tm@findstate\tm@tm;

      \tm@tmfulltrue
      \edef\tm@remtm{\tm@left,\tm@farleft}
      \loop
      \expandafter\tm@mkleft\tm@remtm;
      \iftm@tmfull
      \repeat

      \if\tm@value\tm@blank
      \xdef\tm@result{\tm@result\tm@speca{}\ }
      \else
      \xdef\tm@result{\tm@result\tm@speca{\tm@value}\ }
      \fi

      \tm@tmfulltrue
      \edef\tm@remtm{\tm@right,\tm@farright}
      \loop
      \expandafter\tm@mkright\tm@remtm;
      \iftm@tmfull
      \repeat

      \mbox{}\tm@result\hskip3em(\tm@state)
      }

      \def\tm@mkleft#1,#2;{
      \edef\tm@next{#1}
      \if\tm@next\tm@newworld
      \xdef\tm@result{\tm@spec{}\ \tm@result}
      \else\if\tm@next\tm@blank
      \xdef\tm@result{\tm@result\tm@spec{}\ }
      \else
      \xdef\tm@result{\tm@spec{#1}\ \tm@result}
      \fi\fi
      \edef\tm@remtm{#2}
      \ifx\@empty\tm@remtm
      \tm@tmfullfalse
      \fi
      }

      \def\tm@mkright#1,#2;{
      \edef\tm@next{#1}
      \if\tm@next\tm@newworld
      \xdef\tm@result{\tm@result\tm@spec{}\ }
      \else\if\tm@next\tm@blank
      \xdef\tm@result{\tm@result\tm@spec{}\ }
      \else
      \xdef\tm@result{\tm@result\tm@spec{#1}\ }
      \fi\fi
      \edef\tm@remtm{#2}
      \ifx\@empty\tm@remtm
      \tm@tmfullfalse
      \fi
      }

      \newcount\tm@tmit
      \def\stepandshow#1{%
      \tm@tmit=#1
      \loop
      {\tm@nextstep\showtm}
      \advance\tm@tmit by -1
      \ifnum\tm@tmit>0
      \repeat
      }

      \long\def\runtm{%
      \loop
      {\tm@nextstep\showtm}
      \def\tm@next{no}
      \ifx\tm@next\tm@stopreached
      \repeat
      }

      \def\loopstep#1{%
      \tm@tmit=#1
      \loop
      {\tm@nextstep}
      \advance\tm@tmit by -1
      \ifnum\tm@tmit>0
      \repeat
      }

      \endinput`
      Ho corretto un paio di stupidaggini e, soprattutto, usato comandi “interni” con @ in modo che non sovrascrivano comandi importanti; \value è essenziale in LaTeX, \left e \right sono due primitive piuttosto utili. Chissà a che cosa pensavano.

      Ciao
      Enrico

    • #64335
      Up
      0
      Down
      ::


      Grazie mille, è incredibile ora funziona grazie infinite!
      Sei per caso riuscito a vedere anche il problema con il listings? Ho provato a eseguire il tup .sty e non da né warning ne altro l’unica cosa mi dava erano una marea di bad hbox ma con
      `\begin{lstlisting}[basicstyle=\footnotesize,firstnumber=0,frame=trBL,linewidth=\linewidth,caption={MdT somma},label{MdT:som}]
      &!\showtm
      \runtm!&
      \end{lstlisting}`

      ho risolto. Il problema della prima riga, che è totalmente in più (io l’ho numerata con zero così la prima della MdT è 1) però resta: lei è in più e tutte le altre sotto di lei sono sfasate verso destra uscendo dai margini (con basicstyle=\footnotesize,linewidth=\linewidth evito i bad box ma lo sfasamento e la cornice tutta rotta, nel senso che ogni riga ha il suo pezzettino a margine di cornice, restano)

    • #64336
      Up
      0
      Down
      ::

      Dork” post=63393Grazie mille, è incredibile ora funziona grazie infinite!
      Sei per caso riuscito a vedere anche il problema con il listings? Ho provato a eseguire il tup .sty e non da né warning ne altro l’unica cosa mi dava erano una marea di bad hbox ma con
      `\begin{lstlisting}[basicstyle=\footnotesize,firstnumber=0,frame=trBL,linewidth=\linewidth,caption={MdT somma},label{MdT:som}]
      &!\showtm
      \runtm!&
      \end{lstlisting}`

      ho risolto. Il problema della prima riga, che è totalmente in più (io l’ho numerata con zero così la prima della MdT è 1) però resta: lei è in più e tutte le altre sotto di lei sono sfasate verso destra uscendo dai margini (con basicstyle=\footnotesize,linewidth=\linewidth evito i bad box ma lo sfasamento e la cornice tutta rotta, nel senso che ogni riga ha il suo pezzettino a margine di cornice, restano)

      Versione riveduta e corretta:
      `%=============================================================================
      % Turing — (turing.sty) Style file
      % A LaTeX class for defining and using Turing machines.
      % Author: Mark Schaefer (mark.schaefer@informatik.uni-augsburg.de)
      % University of Augsburg, Germany
      %
      % Copyright (c) 2006 Mark Schaefer
      % All rights reserved.
      %
      % Permission is hereby granted, without written agreement and without
      % license or royalty fees, to use, copy, modify, and distribute this
      % software and its documentation for any purpose, provided that the
      % above copyright notice and the following two paragraphs appear in
      % all copies of this software.
      %
      % IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
      % SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
      % THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED
      % OF THE POSSIBILITY OF SUCH DAMAGE.
      %
      % THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES,
      % INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      % AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
      % ON AN “AS IS” BASIS, AND THE AUTHOR HAS NO OBLIGATION TO
      % PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
      %
      %==============================================================================
      % This package allows the definition, simulation and graphical display of
      % deterministic Turing machines. For the time being this manual assumes that
      % the reader is familiar with this concept.
      %
      % One can initialise a new Turing machine by \newtm(band content).
      % The band entries have to be separated by a ',', after the rightmost entry,
      % no ',' is allowed. start and stop denote states of the Turing machine
      % (obviously, THE start and THE stop state). In general states and band entries
      % can be arbitrary strings, where '-' is used as blank, special characters have
      % to be escaped, e.g. as \# Don't use '=' for states or entries.
      %
      % For example: \newtm(-,1,0,1,0,\#,1,0,1,-)
      %
      % The next-state function is defined by \turingrules{rule1,rule2,…,ruleN}, as
      % for the band entries, rules are separated by ',' and again after the last
      % rule, no ',' is allowed. % Rules have the form
      % (old_state, current_entry, new_state, new_entry, (L|H|R)}.
      %
      % For example: \turingrules{(q0,0,q0,1,R),(q0,1,q0,0,R),(q0,-,stop,-,H)}
      %
      % Note that the next-state function does not have to be complete; an error
      % message is generated if an entry is not found while the old state of the
      % Turing machine is preserved.
      %
      % A graphical representation is generated by \showtm, the following state is
      % generated by \nextstep. Once, the stop-state is reached, \nextstep will have
      % no effect.
      %
      % For convenience, there are the following three commands:
      %
      % – \stepandshow : makes a step and shows the next state, this is repeated times,
      % e.g. \stepandshow{100}
      % – \loopstep
      : same as \stepandshow, but the intermediate results are not printed
      %
      % – \runtm : same as \stepandshow, but the Turing machine stops automatically, if
      % the stop state was reached
      % Caution! The Turing machine may run forever, and so will latex.
      %
      % Have a look at the output of TeX, error messages will be reported there.
      %==============================================================================

      \NeedsTeXFormat{LaTeX2e}[1995/12/01]
      \ProvidesPackage{turing}[2006/02/17]
      \message{This is Turing-Tex.}

      \def\tm@newworld{=}
      \def\tm@blank{-}

      \def\newtm<#1,#2>(#3){%
      \xdef\tm@tm{(=,)(#1)(#3,=,)}%
      \xdef\tm@stopstate{#2}%
      \xdef\tm@stopreached{no}%
      }

      \def\turingrules#1{%
      \xdef\tm@rules{#1,(,,,,),}%
      }

      \def\tm@findstate(#1,#2)(#3)(#4,#5,#6);{%
      \xdef\tm@farleft{#2}%
      \xdef\tm@left{#1}%
      \xdef\tm@state{#3}%
      \xdef\tm@value{#4}%
      \xdef\tm@right{#5}%
      \xdef\tm@farright{#6}%
      }

      \newif\iftm@norulegiven
      \newif\iftm@norulefound

      \def\tm@findrule{%
      \tm@norulegivenfalse
      \tm@norulefoundtrue
      \xdef\tm@remrules{\tm@rules}%
      \loop
      \expandafter\tm@findr\tm@remrules;%
      \iftm@norulefound
      \repeat
      }

      \def\tm@findr(#1,#2,#3,#4,#5),#6;{%
      \edef\tm@stpe{#1}%
      \edef\tm@stpv{#2}%
      \ifx\tm@state\tm@stpe
      \ifx\tm@value\tm@stpv
      \tm@norulefoundfalse
      \xdef\tm@newstate{#3}%
      \xdef\tm@newvalue{#4}%
      \xdef\tm@direction{#5}%
      \fi
      \fi
      \xdef\tm@remrules{#6}%
      \ifx\@empty\tm@remrules
      \tm@norulefoundfalse
      \tm@norulegiventrue
      \fi
      }

      \def\tm@nextstep{%
      \expandafter\tm@findstate\tm@tm;%
      \tm@findrule
      \ifx\tm@newstate\tm@stopstate\xdef\tm@stopreached{yes}\fi
      \iftm@norulegiven
      \ifx\tm@state\tm@stopstate
      \message{Turing machine reached stop state.}%
      \else
      \message{Rule not found for (state,value) (\tm@state,\tm@value)}%
      \fi
      \else
      \def\tm@leftm{L}%
      \def\tm@rightm{R}%
      \def\tm@middlem{H}%
      \if\tm@direction\tm@leftm
      \if\tm@left\tm@newworld
      \xdef\tm@tm{(=,\tm@farleft)(\tm@newstate)(-,\tm@newvalue,\tm@right,\tm@farright)}%
      \else
      \xdef\tm@tm{(\tm@farleft)(\tm@newstate)(\tm@left,\tm@newvalue,\tm@right,\tm@farright)}%
      \fi
      \else\if\tm@direction\tm@rightm
      \if\tm@right\tm@newworld
      \xdef\tm@tm{(\tm@newvalue,\tm@left,\tm@farleft)(\tm@newstate)(-,=,\tm@farright)}%
      \else
      \xdef\tm@tm{(\tm@newvalue,\tm@left,\tm@farleft)(\tm@newstate)(\tm@right,\tm@farright)}%
      \fi
      \else\if\tm@direction\tm@middlem
      \xdef\tm@tm{(\tm@left,\tm@farleft)(\tm@newstate)(\tm@newvalue,\tm@right,\tm@farright)}%
      \fi\fi\fi
      \fi
      }

      \def\tm@spec#1{\vbox{
      \hbox to 1em {\vrule height0.1em depth0.2em\hss#1\hss\vrule height0.1em}\hrule}}
      \def\tm@speca#1{\vbox{\hrule
      \hbox to 1em {\vrule height0.8em depth0.2em\hss#1\hss\vrule height0.8em}\hrule}}

      \newif\iftm@tmfull
      \newif\iftm@nextvalue

      \def\showtm{%
      \xdef\tm@result{}%
      \expandafter\tm@findstate\tm@tm;%
      \tm@tmfulltrue
      \edef\tm@remtm{\tm@left,\tm@farleft}%
      \loop
      \expandafter\tm@mkleft\tm@remtm;
      \iftm@tmfull
      \repeat
      \if\tm@value\tm@blank
      \xdef\tm@result{\tm@result\tm@speca{}\ }%
      \else
      \xdef\tm@result{\tm@result\tm@speca{\tm@value}\ }%
      \fi
      \tm@tmfulltrue
      \edef\tm@remtm{\tm@right,\tm@farright}%
      \loop
      \expandafter\tm@mkright\tm@remtm;%
      \iftm@tmfull
      \repeat
      \mbox{}\tm@result\hskip3em(\tm@state)\par
      }

      \def\tm@mkleft#1,#2;{%
      \edef\tm@next{#1}%
      \if\tm@next\tm@newworld
      \xdef\tm@result{\tm@spec{}\ \tm@result}%
      \else\if\tm@next\tm@blank
      \xdef\tm@result{\tm@result\tm@spec{}\ }%
      \else
      \xdef\tm@result{\tm@spec{#1}\ \tm@result}%
      \fi\fi
      \edef\tm@remtm{#2}%
      \ifx\@empty\tm@remtm
      \tm@tmfullfalse
      \fi
      }

      \def\tm@mkright#1,#2;{%
      \edef\tm@next{#1}%
      \if\tm@next\tm@newworld
      \xdef\tm@result{\tm@result\tm@spec{}\ }%
      \else\if\tm@next\tm@blank
      \xdef\tm@result{\tm@result\tm@spec{}\ }%
      \else
      \xdef\tm@result{\tm@result\tm@spec{#1}\ }%
      \fi\fi
      \edef\tm@remtm{#2}%
      \ifx\@empty\tm@remtm
      \tm@tmfullfalse
      \fi
      }

      \newcount\tm@tmit
      \def\stepandshow#1{%
      \tm@tmit=#1
      \loop
      {\tm@nextstep\showtm}%
      \advance\tm@tmit by -1
      \ifnum\tm@tmit>0
      \repeat
      }

      \long\def\runtm{%
      \loop
      {\tm@nextstep\showtm}%
      \def\tm@next{no}%
      \ifx\tm@next\tm@stopreached
      \repeat
      }

      \def\loopstep#1{%
      \tm@tmit=#1
      \loop
      {\tm@nextstep}
      \advance\tm@tmit by -1
      \ifnum\tm@tmit>0
      \repeat
      }

      \endinput`
      Adesso la riga in più non c’è. Il problema è la cornice tratteggiata dovuta al fatto che le righe sono troppo profonde:
      `\begin{lstlisting}[basicstyle=\linespread{1.4}\footnotesize\ttfamily,%firstnumber=0,
      frame=trBL,linewidth=\linewidth,caption={MdT somma},label={MdT:som}]`
      Ciao
      Enrico

    • #64337
      Up
      0
      Down
      ::


      Dimenticavo! Metti anche \setlength{\parindent}{0pt} prima dell’ambiente lstlisting:
      `\begingroup\setlength{\parindent}{0pt}
      \begin{lstlisting}[…]

      \end{lstlisting}
      \endgroup`
      Ciao
      Enrico

    • #64338
      Up
      0
      Down
      ::


      Senza parole…magico.
      Grazie!

    • #64339
      Up
      0
      Down
      ::


      Perché non scrivi all’autore? Magari invitandolo a pubblicare il pacchetto (corretto) su CTAN?

      Le modifiche consistono in questo:

      – aggiunto il prefisso `tm@` alle macro “private”
      – tolte le righe vuote dove non devono stare
      – messo % dove potrebbe essere aggiunto uno spazio spurio
      – modificata la routine di stampa: la fine capoverso non prima, ma dopo

      Ciao
      Enrico

    • #64340
      Up
      0
      Down
      ::


      Di seguito riporto la e-mail che, come suggerito saggiamente da Egreg,ho scritto all’autore del pacchetto. Sarò felice di riportare anche la sua eventuale risposta. (Spero che il mio inglese non faccia troppa pena).

      Hello, I downloaded your turing.sty package for LaTeX.
      I had need to use it in a document with hyperref and listings packages included and I noticed that there was some problems:
      1-with hyperref package your package didn’t work;
      2-with listings there was an added blank line at the beginning of the printed code and, from the second, all the others were indented at right
      3-the squared code (using listings-frame) was fragmented at every (vertical) line.

      I wrote on the forum of GuIT (http://www.guitex.org/home/), the italian group of LaTeX users, searching a solution and Egreg solve all the problems!

      The changes consist in this:
      -Added prefix `tm@` at macros "private"
      -removed blank lines where there should be;
      -putted % where it could be added a spurious space;
      – changed the routine of press: the end of the paragraph not before but after.

      in this manner, with the code I report under, it work at all.

      I searched for a package like this and in my (and Egreg too) opinion your package is very useful package, and we suggest you to make it public (a correct version) on CTAN.

      In any case I thank you very much.

      With regards.

      Corrado Lanera.

      In attachment your (corrected) turing.sty

      Part of my code:

      `%***************
      \newtm(1,0,1,1,0,1,0,1,\#,1,0,1,1,0,1)
      \turingrules{%
      (next,0,next,0,R),%
      (next,1,next,1,R),%
      (next,0',next,0',R),%
      (next,1',next,1',R),%
      (next,\#,next,\#,R),%
      (next,-,check,-,L),%
      %
      (check,0,prepadd0,-,L),%
      (check,1,prepadd1,-,L),%
      (check,\#,cleanup,-,L),%
      %
      (prepadd0,0,prepadd0,0,L),%
      (prepadd0,1,prepadd0,1,L),%
      (prepadd0,\#,add0,\#,L),%
      (add0,0',add0,0',L),%
      (add0,1',add0,1',L),%
      (add0,-,next,0',R),%
      (add0,0,next,0',R),%
      (add0,1,next,1',R),%
      %
      (prepadd1,0,prepadd1,0,L),%
      (prepadd1,1,prepadd1,1,L),%
      (prepadd1,\#,add1,\#,L),%
      (add1,0',add1,0',L),%
      (add1,1',add1,1',L),%
      (add1,0,next,1',R),%
      (add1,1,propadd1,0',L),%
      (add1,-,next,1',R),%
      (propadd1,0,next,1,R),%
      (propadd1,1,propadd1,0,L),%
      (propadd1,-,next,1,R),%
      %
      (cleanup,0,cleanup,0,L),%
      (cleanup,1,cleanup,1,L),%
      (cleanup,0',cleanup,0,L),%
      (cleanup,1',cleanup,1,L),%
      (cleanup,-,stop,-,H)%
      }

      \begingroup\setlength{\parindent}{0pt}
      \begin{lstlisting}[basicstyle=\footnotesize\linespread{1.4}\ttfamily,
      frame=trBL,linewidth=\linewidth,caption={MdT somma},label={MdT:som}]
      &!\showtm
      \runtm!&
      \end{lstlisting}
      \endgroup
      %****************`

    • #64341
      Up
      0
      Down
      ::


      Io avrei scritto così:

      Hello, I downloaded your turing.sty package for LaTeX.

      I needed to use it in a document using the hyperref and listings packages and I noticed that there were some problems:

      1 – with the hyperref package your package didn’t work;
      2 – with listings there was a spurious blank line at the beginning of the printed code and, starting from the second, all the others were indented
      3 – the framed code (using listings frames) was fragmented at every (vertical) line.

      I wrote about this on the GuIT forum (www.guitex.org/home/), the Italian group of LaTeX users, to ask for a solution and Egreg solved all the problems!

      The changes consisted in this:
      – the prefix `tm@` was added before “private” macro names;
      – some wrong blank lines were removed;
      – % was inserted where it could add a spurious space;
      – the printing routine was changed, calling end-of–paragraph at the end and not at the start.

      in this way, with the code I enclose below, the document was typeset correctly.

      I had searched for a package like this and in my (and Egreg too) opinion your package is very useful one, so we suggest you to publish it on CTAN.

      In any case I thank you very much.

      Best regards.

      Tizio Semproni.

      Enclosed a corrected version of turing.sty

      “Putted”? 🙂

      Ciao
      Enrico

    • #64342
      Up
      0
      Down
      ::


      Oddio, anche “routine of press” per dire “routine di stampa” ha qualcosa che non va… 😕
      Se inviavi il messaggio qui sul forum prima di inviarglielo, eravamo lieti (almeno io) di darti brevemente una mano; capisco che non è l’obiettivo principale del forum, ma ne va della chiarezza di una comunicazione tra gli amanti di TeX/LaTeX.

      Facci sapere cosa ti risponde.

      Ciao e grazie,
      Antonio

    • #64343
      Up
      0
      Down
      ::


      L’autore non ha ancora risposto, in compenso ho trovato qualche altro problema…
      Mi servirebbe mostrare (semplicemente) la mdt in una configurazione che non si a la prima e quindi con la testina non all’inizio e uno stato non quello iniziale. La soluzione che3 ho trovato (e in parte funziona) è la seguente

      `\newtm(\#,$w_1$,-,-,-,$w_N$,$u_1$,-,-,-,-,$u_M$,-)
      \turingrules{%
      (s,\#,s,\#,R),%
      (s,$w_1$,s,$w_1$,R),%
      (s,-,s,-,R),%
      (s,$w_N$,q,$w_N$,H)%
      }
      \begingroup\setlength{\parindent}{0pt}
      \begin{lstlisting}[numbers=none,float=htbp,basicstyle=\linespread{1.4}\ttfamily,
      frame=trBL,linewidth=\linewidth,caption={MdT: configurazione},label=mdt:config]
      &!\loopstep{6}
      \showtm
      !&
      \end{lstlisting}
      \endgroup
      `

      ora, a parte che devo usare \loopstep{} perchè \nextstep pare non funzionare, il risultato è che la visualizzazione del nastro dentro la cella del listings è giustificata a destra, contrariamente a tutte le altre che lo sono a sinistra. Inoltre nel caso della sequenza \showtm \runtm la prima stringa resta comunque indentata un po’ sulla destra rispetto alle altre, nonostante il bordo della listings sia perfetto.
      Se riuscite a risolvere anche questo grazie mille 🙂

Visualizzazione 9 filoni di risposte
  • Devi essere connesso per rispondere a questo topic.

Go to top