Posting Code as a File

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
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
 

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
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
 

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
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
 

bertus

Joined Apr 5, 2008
22,270
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
 

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
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
 

bertus

Joined Apr 5, 2008
22,270
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.
 

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
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
 
Top