Posting Code as a File

Discussion in 'Feedback and Suggestions' started by jpanhalt, Mar 21, 2015.

  1. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    I recently posted a completed project that had a relatively short code attachment of 3 pages. My options were to post it as a file that gets totally butchered when it is opened, or post it with code tags that would then be quite lengthy. Is there something in between?

    I have been trying with Adobe Acrobat to make a PDF that would open like a regular PDF and retain the formatting. Unfortunately, my Acrobat is ver. 8 (circa 2007), and I can't get it to work. It would be neat, if we could use the code tags to make a file that could then just be attached.

    John
     
  2. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,811
    834
    John,

    Have you tried a free online PDF converter? This is one that I've used. I copy my code to a file with a .txt extension and then convert it.
     
  3. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,348
  4. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    Hi Bertus,

    The problem is not getting into a .txt or .pdf extension, it is preserving the formatting.

    I use MPLab and write in Assembly (MPASM). As you know, that code is laid out by "columns." The columns have significance. Memory banking is another important aspect, particularly with the mid-range and enhanced mid-range devices. So, as an aid to me while writing, but also to others who might read it, I include a column on the far right showing the Bank where it is not plainly obvious from context (e.g., ";<comment> |B3" for something done in Bank3). MPLab gives on the choice of using tabs, using spaces, or using tabs that get replaced by spaces. I pick the latter, as tabs alone really creates a mess. Nevertheless, things that are nicely lined up in an MPLab .asm file get really mixed up when opened as a .txt file. Pommie ( a member here) posted a little routine called "CodeTidy" that does a pretty good job of converting .asm to .txt, but still it is not perfect. The greatest problem is with the Bank column. I like my bank designations to line up nicely. Part of the problem may be that I use an 80-column page. I have not experimented with that variable. My other settings are a gutter of 4 spaces, and a tab of 5 spaces. The gutter might also be part of the problem.

    Anyway, the new code tags that came with XenForo, particularly when "{code=asm}" is used work OK. Not perfect, but certainly more readable than a simple .txt conversion and almost as good as using CodeTidy. One thing I like particularly about using code tages is that color is retained. That benefit is lost in CodeTidy.

    What prompted my question was whether a file with code tags could be saved as an attachment, rather than inserted in the text, so that when it was opened, the formatting would be retained.

    Some things I have tried that don't work:
    1) Tried cut and paste into Word 2007. The macros in my code drove that program nuts.
    2) Was able to get Adobe Acrobat 8 Pro to convert a text file that had been doctored by CodeTidy to a .pdf. The result was better than trusting to the portability of a .txt file alone, but was not as good as I would want considering the effort involved.
    3) Acrobat 8 will not take a .asm file directly.

    Regards,
    John
     
  5. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,348
    Hello,

    You can attach an .asm file in the forum, as it is one of the allowed file formats.

    Bertus
     
  6. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    Yes, I did that in the projects forum. But then people have to open in MPLab with the same settings I use, which are stated in the header.

    Here is how I would like it to look:
    upload_2015-3-22_5-34-20.png


    Here is the same section opened by double clicking on my .asm attachment:


    Capture.PNG

    That particular section had been adjusted with spaces and is readable, but not all are that good, and if there are any keyboard graphics like this:

    upload_2015-3-22_5-40-6.png

    They become completely undecipherable. In this case the numbers on the square wave are intended to help the reader know exactly where the timing interrupts used in the code are.

    John
     
  7. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,348
    Hello,

    What would happen when you use code=plain as code opening tag?
    Normaly the code tags should set the monospaced font and preserve spaces.
    The code is represented by "courier new" font at 10 pt

    Bertus
     
  8. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    Hi bertus,

    Thanks for working with me on this. I couldn't see much change using the code=plain tag. It appears that regular in-line code without the bank comment or graphics looks OK. Let me play with some other options and see if I can come up with a work-around. I have a suspicion part of the problem is my page width.

    John
     
  9. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,348
    Hello,

    It looks as if the tabs to spaces translation goes wrong.
    Did you try to change the tab settings in word or notepad?
    As said LibreOffice can make a PDF file from a text.

    Bertus

    PS can you post the .asm file without putting it into the post?
    I have LibreOffice installed here and want to try to convert it to PDF.
     
  10. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,811
    834
    And I'll try to convert it using freepdfonline
     
  11. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    MPLab converts tabs to spaces. At least, it is supposed to. CodeTidy definitely does that conversion too. I will take a look now at the columns.

    I use a wide screen, like probably most people in the US do today, and so 80 columns or even more is quite easy to handle.

    @djsfantasi : The header part with keyboard graphics is probably going to be the hardest nut to crack. I can work around that for the times I will be posting something here.

    John
     
  12. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    Test

    Changed width to 60, used CodeTidy, spent a few minutes on a couple outliers, saved as .txt and attached here. Looks better on my machine.

    John
     
  13. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    Here it is uploaded as a .asm file.

    Edit: Format looks pretty good. Just no pretty colors. I can live with that.

    John
     
  14. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,348
    Hello,

    The ASM file opens perfect in kwrite on my linux machine.

    Bertus
     
Loading...