Codice Python

  • Creatore
    Topic
  • #61064
    Up
    0
    Down
    ::


    Ragazzi, quando inserisco in appendice del codice Python succede una cosa strana..

    Infatti, mi mette – al posto degli spazi – alcuni caratteri strani, tipo delle “u” squadrate e basse..

    Ma non sempre.

    Sapete come posso toglierle?

Visualizzazione 8 filoni di risposte
  • Autore
    Risposte
    • #61065
      Up
      0
      Down
      ::


      Che pacchetto usi per formattare i codici? listings?

      Probabilmente hai messo l’opzione showspaces=true.

      Ciao ciao.
      Fra

    • #61066
      Up
      0
      Down
      ::


      Uso listings, ma senza opzioni.. Il punto è che non lo fa per tutti gli spazi..
      Ora sono in ufficio. Stasera ti faccio vedere il pdf, se vuoi!

      Puoi provare a darmi il codice per mettere l’off.?

      Magari funziona!

    • #61067
      Up
      0
      Down
      ::


      Uso raramente listings. Immagino sia showspaces=false
      (non era difficile 😀 anche se secondo me dovrebbe essere disabilitato
      di default)!
      Alcuni si mostrano altri no…? Forse perché alcuni sono spazi altri sono
      tabulazioni. Non so.

      Costruisciti un esempio minimale a parte rispetto al tuo documento
      e vedrai che troverai dov’è il problema. Nel frattempo ovviamente
      prova a guardare la documentazione di listings.

      Ciao ciao.
      Fra

    • #61068
      Up
      0
      Down
      ::


      Stasera provo e se non riesco posto qui un minimal che dia lo stesso problema. Magari mi sapete aiutare ;).
      Thanks.

    • #61069
      Up
      0
      Down
      ::


      Ecco qui l’esempio..
      Prima il mio file tex:
      `
      \documentclass [12pt,a4paper,twoside,disablefront]{suftesi}

      %———————-Definition of usefull packages
      \usepackage[italian,english]{babel}
      \usepackage[utf8]{inputenc}
      \usepackage[T1]{fontenc}
      \usepackage{lmodern}
      \usepackage{graphicx}
      \usepackage{caption}
      \usepackage{amsfonts}
      \usepackage{fancyhdr}
      \usepackage{color}
      \usepackage{lastpage}
      \usepackage{longtable}
      \usepackage{amsmath}
      \usepackage{texdraw}
      \usepackage{makeidx}
      \usepackage{epigraph}
      \usepackage{natbib}
      \usepackage{verbatim}
      \usepackage{multicol}
      \usepackage{float}
      \usepackage{listings}
      \usepackage{textcomp}
      \usepackage{alltt}
      \usepackage{ifpdf}
      \usepackage{subfig}
      \usepackage{geometry}
      \usepackage{emptypage}
      \renewcommand\lfoot[2][]{}
      \renewcommand\cfoot[2][]{}
      \renewcommand\rfoot[2][]{}
      \renewcommand\lhead[2][]{}
      \renewcommand\chead[2][]{}
      \renewcommand\rhead[2][]{}
      %\usepackage{doxygen}

      %———————-Magia
      \providecommand{\csletcs}[2]{%
      \expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname}
      \newcommand{\equivUC}[3][\def]{%
      \expandafter#1\csname#2\expandafter\endcsname\expandafter{%
      \csname#3\endcsname}}
      \newcommand{\UPCASElang}[1]{
      \uppercase{\def\temp{#1}}
      \csletcs{l@\temp}{l@#1}
      \equivUC{date\temp}{date#1}
      \equivUC{captions\temp}{captions#1}
      \equivUC{extras\temp}{extras#1}
      \equivUC{noextras\temp}{noextras#1}
      \equivUC[\edef]{\temp hyphenmins}{#1hyphenmins}
      }
      \UPCASElang{english}
      \UPCASElang{italian}

      \ifpdf
      \usepackage[pdftex,
      pagebackref=true,
      colorlinks=true,
      citecolor=blue,
      linkcolor=black,
      unicode
      ]{hyperref}
      \else
      \usepackage[ps2pdf,
      pagebackref=true,
      colorlinks=true,
      citecolor=blue,
      linkcolor=black,
      unicode
      ]{hyperref}
      \usepackage{pspicture}
      \fi

      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      %SONO QUELLI CHE HO AGGIUNTO “A NASO”..
      \lstset{language=C++,inputencoding=utf8,basicstyle=\footnotesize,breaklines=true,breakatwhitespace=true,tabsize=8,numbers=left }
      \renewcommand{\footrulewidth}{0.4pt}
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

      %———————-Set Toc Counter
      \setcounter{secnumdepth}{4}
      \setcounter{tocdepth}{4}

      \newenvironment{abstract}
      {\cleardoublepage\thispagestyle{empty}\vspace*{\fill}
      \begin{center}\bfseries\abstractname\end{center}}
      {\par\vfill}

      % parte di fancyhdr
      \pagestyle{fancy}
      \fancyhf{}
      \renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
      \fancypagestyle{fncymain}{%
      \renewcommand{\headrulewidth}{0.4pt}%
      \fancyhf{}%
      \fancyhead[LE]{\bfseries\chaptername\ \thechapter}%
      \fancyhead[RO]{\bfseries\nouppercase{\leftmark}}%
      \fancyfoot[LE,RO]{\thepage}}
      \fancypagestyle{fncyfront}{%
      \renewcommand{\headrulewidth}{0.4pt}%
      \fancyhf{}%
      \fancyhead[LE]{\bfseries\nouppercase{\leftmark}}%
      \fancyhead[RO]{\bfseries\nouppercase{\leftmark}}%
      \fancyfoot[LE,RO]{\thepage}}

      %———————-Commands to avoid head/footnote at the end of each chapter
      \fancypagestyle{plain}{\fancyhf{}%
      \fancyfoot[C]{\thepage}%
      \renewcommand\headrulewidth{0pt}%
      \renewcommand\footrulewidth{0pt}}
      \makeatletter
      \def\cleardoublepage{\clearpage\if@twoside
      \ifodd\c@page
      \else\hbox{}\thispagestyle{empty}\newpage
      \if@twocolumn\hbox{}\newpage\fi\fi\fi}
      \makeatother

      %———————-Definition of new commands
      \newcommand{\fncyblank}{\fancyhf{}}

      \newcommand{\vtk}{\textit{VTK}}
      \newcommand{\vmtk}{\textit{VMTK}}
      \newcommand{\vmtkgui}{\textit{VMTKGui}}
      \newcommand{\virtualvalvestent}{\textit{VirtualValveStent}}
      \newcommand{\ct}{\textit{CT}}
      \newcommand{\dicom}{\textit{DICOM}}
      \newcommand{\mr}{\textit{MR}}
      \newcommand{\cfd}{\textit{CFD}}
      \newcommand{\gui}{\textit{GUI}}
      \newcommand{\lss}{\textit{LSS}}
      \newcommand{\fe}{\textit{FE}}
      \newcommand{\python}{\textit{Python}}

      %———————-Beginning Document
      \begin{document}

      %———————-frontmatter
      \pagestyle{fncyfront}
      \frontmatter

      %———————-Mainmatter
      \pagestyle{fncymain}
      \mainmatter
      \pagenumbering{arabic}
      \appendix
      In this chapter we list all the files needed to run the tool we have developed. This is a very technical appendix and it is addressed to people who want to develop and study what there is under the hood.
      \section{vmtkgui.py}
      This is the “main'' file and it contains all the links between the different files.
      \lstinputlisting{vmtkgui.py}

      %———————-Backmatter
      \end{document}
      `

      e qui il file Python.

      `
      ## Function used to load a DICOM file
      # @param self The object pointer
      # @param widget gdk widget
      def call_dicom_path (self, widget):
      print “Trying to load the DICOM file”
      # planeWidgetX.InteractionOff()
      # planeWidgetY.InteractionOff()
      # planeWidgetZ.InteractionOff()
      # interactorStyle.EnabledOn()

      ## This is the command we need in order to smooth the surface.
      # @param self The object pointer
      # @param widget gdk widget
      def call_viewimg (self, widget):
      self.vmtkinterface.imageviewer()

      ## This is the command we need in order to smooth the surface.
      # @param self The object pointer
      # @param widget gdk widget
      def call_viewsurf (self, widget):
      self.vmtkinterface.surfaceviewer()

      ## This is the command we need in order to smooth the surface.
      # @param self The object pointer
      # @param widget gdk widget
      def call_viewmesh (self, widget):
      print “Il bottone funziona!”
      self.vmtkinterface.meshviewer()
      `

      Noto che “segna gli spazi” quando c’è una frase tra virgolette. Idee??

    • #61070
      mcl1962
      Partecipante
        Up
        0
        Down
        ::


        Il comportamento descritto è tipico di

        showstringspaces=true

        (è corretto che gli spazi siano segnati solo all’interno delel stringhe). Prova ad aggiungere quanto segue dopo \begin{document}:

        \lstset{language=Python, showspaces=false, showstringspaces=false}

        Ciao.

        Claudio

      • #61071
        Up
        0
        Down
        ::


        La risposta corretta te l’ha data Claudio 🙂

        Ti faccio notare alcune cose:

        1. Sei sicuro che ti servano veramente tutti quei pacchetti?
        2. Rimango molto perplesso di fronte all’uso di texdraw…
        3. Dato che usi listings, verbatim ti serve davvero?
        4. Stesso discorso per alltt
        5. e ifpdf?
        6. I filetti sia sopra che sotto sono piuttosto bruttini, ma questi sono gusti…
        7. \pagenumbering{arabic} credo sia inutile dato che usi \mainmatter

        Ciao ciao.
        Fra

      • #61072
        Up
        0
        Down
        ::

        La risposta corretta te l’ha data Claudio

        Ottimo. Grazie Claudio!

        Ti faccio notare alcune cose:

        Grazie.. C’è sempre da imparare!

        1. Sei sicuro che ti servano veramente tutti quei pacchetti?

        Onestamente no! Diciamo che “nel troppo ci sta tutto.. Però ora provo a pulirla un po!

        2. Rimango molto perplesso di fronte all’uso di texdraw…

        Provo a toglierlo 😉

        3. Dato che usi listings, verbatim ti serve davvero?

        In effetti no!

        4. Stesso discorso per alltt

        Provo a toglierlo!

        5. e ifpdf?

        ??

        6. I filetti sia sopra che sotto sono piuttosto bruttini, ma questi sono gusti…

        Non ho capito. Cosa sono “i filetti”?

        7. \pagenumbering{arabic} credo sia inutile dato che usi \mainmatter

        Se lo tolgo va avanti la numerazione romana. Forse perché uso la classe surftesi?

        Ora un’altra domanda: ma mettere tanti pacchetti che problemi comporta?

      • #61073
        Up
        0
        Down
        ::


        ifpdf è un pacchetto che ti permette di usare dei comandi per
        poter distinguere se si sta compilando il documento con pdflatex
        o latex.

        Tu lo usi nel seguente if:
        `\ifpdf
        \usepackage[pdftex,
        pagebackref=true,
        colorlinks=true,
        citecolor=blue,
        linkcolor=black,
        unicode
        ]{hyperref}
        \else
        \usepackage[ps2pdf,
        pagebackref=true,
        colorlinks=true,
        citecolor=blue,
        linkcolor=black,
        unicode
        ]{hyperref}
        \usepackage{pspicture}
        \fi `

        Sostituisci tutto con
        `\usepackage[pagebackref=true,colorlinks=true,citecolor=blue,linkcolor=black,unicode]{hyperref}
        `
        (non credo che tu usi l’ambiente picture vero?)

        I filetti sono quelle righe orizzontali che hai messo sopra e sotto alle pagine.

        A me la numerazione diventa araba… strano.

        Mettere tanti pacchetti comporta che il codice ci mette di più per essere compilato,
        inoltre aumentano i possibili conflitti tra i pacchetti, soprattutto quando si usano
        pacchetti diversi pensati per fare le stesse cose. Insomma più il codice è complicato
        tanto più è facile che incappi in qualche problema ed è tanto più difficile scovare
        l’errore. E poi non è da sottovalutare l’aspetto estetico del codice: se lo ripulisci
        tendi a imparare quali pacchetti ti servono veramente e quindi cominci a orientarti
        nel mondo TeX.

        Ciao ciao.
        Fra

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

    Go to top